Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove the first column of every row?

Tags:

jquery

I am having trouble trying to remove the first column from every row. I have a felling it is my understanding of jquery.

I've tried the following.

$("table:eq(2) tr td:first").remove() // this only removed the first cell

$("table:eq(2) tr td:first").each.remove() // didn't notice a difference

Any ideas of what I'm doing wrong?

like image 770
PhoenixDown Avatar asked Feb 19 '11 01:02

PhoenixDown


1 Answers

Try using td:first-child instead of td:first

See this page for more: http://api.jquery.com/first-child-selector/

P.S. A couple of suggestions for your jQuery selector:

  1. Use a table id or class instead of index identification because if you move your table in the DOM, your selector will break

  2. I'm pretty sure you don't need the "tr"

So:

 $("#myTable td:first-child").remove()
like image 134
Karim Avatar answered Nov 17 '22 13:11

Karim