Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Context within a jQuery selection

Tags:

jquery

I have the following:

<p class="myClass">This is a paragraph
<div>div within the paragraph</div>

More text in the paragraph
</p>

My jQuery is:

var X = $('div','.myClass');
PRINT(X);
PRINT(X.length);
PRINT(X.selector);

X.selector is: .myClass div, which is what I expected, but X.length=0.

Q: What am I not understanding about context? It also doesn't work if I change it to

var X = $('.myClass div');
like image 356
Phillip Senn Avatar asked Jan 17 '26 01:01

Phillip Senn


1 Answers

This probably isn't the answer to your question, but you shouldn't (maybe even can't) use a 'div' inside a 'p'. You should try using a 'span' inside a 'p'.

like image 158
Luke Avatar answered Jan 19 '26 15:01

Luke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!