开发者

jQuery selector help

开发者 https://www.devze.com 2022-12-11 12:05 出处:网络
Good Morning, I am trying to write a selector that would select all rows that contain a span element that has a class of \"cancelMenu\".

Good Morning,

I am trying to write a selector that would select all rows that contain a span element that has a class of "cancelMenu".

Is either of these better than the other? Or is there an even better way to write it?

 $("span.cancelMenu").closest("tr");
 $("tr > span.cancelMenu");

Any thoughts or ideas? I am using the first one and it work开发者_StackOverflow中文版s but it seems like I am only targeting one row. I really want all rows at once.

Thanks, ~ck


You can the :has pseudo-selector:

$("tr:has(span.cancelMenu)");


$("tr:has(span.cancelMenu)");


if you want to select the row (tr) and not the span you can use parent():

$('span.cancelMenu').parent('tr'); 


I'd probably go with something like

$("span.cancelMenu").each(function(i) {
   //$(this).parent() is the row
});
0

精彩评论

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