how to remove the first column of every row?
I am having trouble trying to remove the first column from every row. I have a felli开发者_C百科ng 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?
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:
Use a table id or class instead of index identification because if you move your table in the DOM, your selector will break
I'm pretty sure you don't need the "tr"
So:
$("#myTable td:first-child").remove()
Try this:
$("table:eq(2) tr").each(function(){
$(this).find("td:first").remove();
});
See it here: http://jsfiddle.net/cnanney/yZQdU/
Edit: I like Karim's answer better :)
$("table:eq(2) tr td:first-child")
is much cleaner, not to mention more efficient.
精彩评论