0

How do I select the following in JQuery?

<div class='A'>
  <span class='B C'>
     <p class='C D E'>
     </p>
  </span>
</div>

The following isn't working.

$('div.A > span.B.C > p.C.D.E')
3
  • Read the CSS Selectors, Level 3 spec, and the jQuery API documentation, and come back if you have any problems, after showing an actual attempt (not just "thinking about" one), and explaining the problem. Also: explain what you're trying to select. Commented Feb 28, 2016 at 14:28
  • Which element are you attempting to target? The + selector wouldn't appear to be appropriate in this case as it selects siblings, not children. Commented Feb 28, 2016 at 14:31
  • This was solved by this answer. Commented May 12, 2022 at 9:16

1 Answer 1

1

You could do $('.A').find('p.C')

https://api.jquery.com/find/

.find() : Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.

Sign up to request clarification or add additional context in comments.

1 Comment

It would be great if the people down-voting could leave a reason why.

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.