tags:

views:

54

answers:

4

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 works but it seems like I am only targeting one row. I really want all rows at once.

Thanks, ~ck

+5  A: 

You can the :has pseudo-selector:

$("tr:has(span.cancelMenu)");
CMS
this will select the span, non the row
gpilotino
won't that select the `span` and not the `tr` ?
Soufiane Hassou
Yes, misread, edited...
CMS
+1  A: 

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

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

gpilotino
+2  A: 
$("tr:has(span.cancelMenu)");
Russ Cam
A: 

I'd probably go with something like

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