Jurja
Jurja

Reputation: 3

weird behavior with jquery

I've removed previous question because I found the problem is in jQuery itself.

Imagine this code :

var el = $('<ul><li/></ul><a id="clickMe">click me!</a><p>').find('#clickMe');

Why the clickMe isn't found ?

Upvotes: 0

Views: 29

Answers (1)

A. Wolff
A. Wolff

Reputation: 74420

Because .find() looks for descendants, use in your case filter() instead:

var el = $('<ul><li/></ul><a id="clickMe">click me!</a><p>').filter('#clickMe');

DEMO

NOTe: in your html string, you are not closing <p> tag.

Upvotes: 1

Related Questions