Reputation: 240
I'm using a CMS that doesn't let me edit the HTML, I can only use JavaScript and HTML to customize the way it looks. There's a page with 3 tables and I want to remove (or hide) the 2nd column from the 2nd table. Here's the HTML code:
<TABLE>
<TR>
<TD> </TD>
<TD> </TD>
</TR>
<TR>
<TD> </TD>
<TD> </TD>
</TR>
</TABLE>
<TABLE>
<TR>
<TH>Row 1</TH>
<TH>Row 2</TH>
<TH>Row 3</TH>
</TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD> </TD>
</TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD> </TD>
</TR>
</TABLE>
<TABLE>
<TR>
<TH>Row 1</TH>
<TH>Row 2</TH>
<TH>Row 3</TH>
</TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD> </TD>
</TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD> </TD>
</TR>
</TABLE>
How do I remove JUST the second column in the second table?
Upvotes: 1
Views: 6977
Reputation: 1730
I have seen that the tables do not have ids. So @blackpla9ue's answer is the most appropriate. But if you need to remove the second row of a table which has an id then go for the below code.
$('td:nth-child(2), th:nth-child(2)', '#tblEventSearchResults tr').css('background', '#f00');
Upvotes: 0
Reputation: 1176
Using jquery: http://jsfiddle.net/upeVs/
$('table:eq(1) tr td:nth-child(2),table:eq(1) tr th:nth-child(2)').remove();
Edit:
Solution given by @blackpla9ue
is maybe a little bit more performant given that it only once looks for the table row:
$('td:nth-child(2), th:nth-child(2)', 'table:eq(1) tr').remove();
Upvotes: 1
Reputation: 3423
Check this fiddle : http://jsfiddle.net/FJfbW/1/
$('td:nth-child(2), th:nth-child(2)', 'table:eq(1) tr').css('background', '#f00');
You can use .remove()
without using .css()
to get rid of the column
Upvotes: 4