tags:

views:

27

answers:

3

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.

Just can't figure out the notation.

Any suggestions please?

Pete

A: 

Yes.It have.

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

You can use:

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

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

Evan Trimboli
@Evan,your answer is only similar to $('#somediv > p'). It is different with $('#somediv p')
Kai
A: 

This should do it:

$mydiv.find('p');
Eikern
the extra $() is not needed. $mydiv already refers to a jquery object.
Jamiec
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
Pete
@Jamiec my mistake - wrote it in a hurry.
Eikern