开发者

jQuery selector help

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜