Control Freak
Control Freak

Reputation: 13243

Find if selector exists in variable

How do you find out if the data retreived from a .get() request contains html with a certain selector?

 $.get(url,function(data){   alert( data.find("#myid").length )  });

Doesn't seem to work.

Upvotes: 0

Views: 70

Answers (2)

Denys Séguret
Denys Séguret

Reputation: 382514

Supposing data is some HTML, use

$(data).find("#myid").length

or this more reliable solution if your document isn't well formed :

$("<div>").html(data).find("#myid")

Upvotes: 4

NibblyPig
NibblyPig

Reputation: 52962

You should be doing $(data).find

Upvotes: 1

Related Questions