4

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

html = '<a href="http://www.site.com"><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.

1 Answer 1

8

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

$("<div>"+html+"</div>").find("a").length
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.