3

I need some help. Code below doesn't work just like i needed.

What I want here: With the help of JavaScript I want to hide or make a table column invisible which has id myid.

$(document).ready(function(){	
  document.getElementById( 'myid' ).style.display = 'none';
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table width="200" border="1">
  <tr>
    <td id="myid">x</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

thanks in advance!

5
  • It does work....jsfiddle.net/rayon_1990/uxLjLcaz Commented Feb 15, 2016 at 11:52
  • use $('#myid').hide(); in document ready function Commented Feb 15, 2016 at 11:52
  • Your code seems to be working just fine? jsfiddle.net/Bjolja/kftfgpke darn... too slow Commented Feb 15, 2016 at 11:53
  • hello pochen here in my browser not fine Commented Feb 15, 2016 at 11:55
  • you should try to get away from using width, border, etc.. on tables. Try to solve this using CSS Commented Feb 15, 2016 at 15:53

4 Answers 4

2

Use jquery like this :

$(document).ready(function(){   
  $("#myid").hide(); 
});

Hope this helps :)

Sign up to request clarification or add additional context in comments.

Comments

2

maybe you want to hide entire column by the id of a table cell

something like this

<body>
<table width="200" border="1">
  <tr>
    <td id="myid" class="col0">x</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
 </tr>
  <tr>
    <td class="col0">x</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
 </tr>
</table>
</body>



$(document).ready(function(){   
    var className = $('#myid').attr('class')
  console.log(className)
  $('.'+className).hide()
});

Comments

2

I don't think you added the jquery in your code. Your code is working. Check this FIDDLE

Add this line in your html:

<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>

3 Comments

i will try and report it to you
Yes isragrab it works manythanks
You're welcome @Devisy. Since you're new here, please don't forget to mark the answer accepted which helped most in solving the problem. See also How does accepting an answer work (meta.stackexchange.com/questions/5234/…)?
1

Change the ids with a classname that repeats in all column. The reason is that ids are unique and you must not duplicate them.

$(document).ready(function(){   
  $('.myid').hide()
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<table width="200" border="1">
  <tr>
    <td class="myid">x</td>
    <td>&nbsp;</td>
    <td>x</td>
  </tr>
  <tr>
    <td class="myid">y</td>
    <td>&nbsp;</td>
    <td>y</td>
  </tr>
</table>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.