0

I am using variables to hold jquery objects as

$mydiv = $('#somediv');

Now I would like to extend this to reference a paragraph within $mydiv. Obviously you could declare a new variable

$mypara = $('#somediv p')

But is there any way to extend the $mydiv variable to find the paragraph it contains.

I just can't figure out the right notation to do this.

3 Answers 3

1

This should do it:

$mydiv.find('p');
Sign up to request clarification or add additional context in comments.

3 Comments

the extra $() is not needed. $mydiv already refers to a jquery object.
Thanks guys $mydiv.find does the trick. Love jquery you seem to be able to do most things - if only you can work out how to construct it! Pete
@Jamiec my mistake - wrote it in a hurry.
0

You can use:

var = mydiv = $('#somediv');
var children = mydiv.children('p');

This will give you all the child 'p' elements belonging to your div.

1 Comment

your answer is only similar to $('#somediv > p'). It is different with $('#somediv p')
0

Yes.It have.

$mydiv = $('#somediv');
$mydiv.find('p');

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.