0

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

1
  • 1
    The second selector is selecting the span, not the tr. Commented Nov 17, 2009 at 15:38

4 Answers 4

5

You can the :has pseudo-selector:

$("tr:has(span.cancelMenu)");
Sign up to request clarification or add additional context in comments.

2 Comments

this will select the span, non the row
won't that select the span and not the tr ?
2
$("tr:has(span.cancelMenu)");

Comments

1

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

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

Comments

0

I'd probably go with something like

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.