mercredi 1 juillet 2015

How to access the root element when parsing HTML with jQuery?

How do I access the root element when parsing HTML with jQuery?

More specifically, why does this equals to 0:

$('<div class="messages"><p>Just a test.</p></div><div class="messages">Another test</div>')
    .find('div.messages').length == 0

Where this equals to 1 like it should:

$('<div><div class="messages"><p>Just a test.</p></div></div>')
    .find('div.messages').length == 1

Okay, I can wrap everything into something every time, but really do I have to?

JSFiddle

Aucun commentaire:

Enregistrer un commentaire