3

If this is an HTMLDivElement, how do I avoid doing this ?

$('#' + $(this).id + " > p").foo();

to do something like :

($(this) + $( " > p")).foo();

2 Answers 2

9
$(this).children('p').foo();
Sign up to request clarification or add additional context in comments.

2 Comments

I was hoping to concatenate more in the string, but for this children would do.
You can use .find to select any descendants matching a selector, if you don't want direct children.
3

Try this:

$(this).find("> p").foo();

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.