Let\'s suppose I have
var testHTML = \"\";
I want to get above div as JQuery object
You could use the .search() function of the javascript itself.
testHTML.search('demo_div')>-1
The problem is that your div
is the root element in the collection, so you need to use .filter() instead of .find() (which only looks at descendant elements):
var found = $(testHTML).filter("#demo_div");
I'm assuming your actual HTML string is more complex than the one in the question, otherwise you don't need to do anything other than $(testHTML)
and you will have a jQuery object containing that single element.