views:

95

answers:

1

I am not able to traverse a custom html string with Jquery, like in this example:

html = '<a href="http://www.site.com"&gt;&lt;img width="800" src="http://www.site.com/pic.jpg" alt="" /></a><br /><br />Description<br />';
found = $(html).find("a").length;

"found" returns 0, while I would expect to get 1

I suspect I'm doing something really stupid here, but after hours I still don't see what's wrong.

+4  A: 

You need to put your HTML code into a “root element” like a DIV:

$("<div>"+html+"</div>").find("a").length
Gumbo
Works fine, thanks!
UVL