开发者

How to remove a table row using jQuery

开发者 https://www.devze.com 2023-04-04 21:24 出处:网络
Just want to know how to select a table row by id eg the table row has the id of \"50\" ... How can I select this 开发者_开发问答(as I wish to use the hide() function on a click)$(\'tr#50\').click(

Just want to know how to select a table row by id

eg the table row has the id of "50"

...

How can I select this 开发者_开发问答(as I wish to use the hide() function on a click)


$('tr#50').click(function(ev) { $(this).hide(); });

$('tr#50') selects the row. .click(function(){...}) runs the function when you click on the row. $(this) is a way of selecting the original element that you set the click handler on (in this case, that selected by "tr#50"). And .hide(), obviously, hides that element.

EDIT: As other answerers point out, it's not good practice to start an id with a number, and even worse practice to make your id only a number. You should rename it to something like row-50.


write this on Click event

 $('tr#50').hide()

But i would suggest you that don't start your id with Number as it's not a good practice ...


$('tr#50')

be careful with number-only ids though


To select an element with an id just use the following selector:

$("tr#id").hide();

So for your problem with the id 50 it would be:

$("tr#50").hide();


If you don't have an ID of the table and simply wants to select the 50th row, you can select it with:

$('table tr').eq(49);

or

$('table tr:eq(49)');

Note that eq() starts on 0, and not 1. There for the eq() in this case is (50 - 1)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号