Can I use jQuery selectors on an HTML string that is not attached to the DOM? -


so if have variable like

var ht = "<body><p>paragraph here</p></body>" 

if attached dom text

$('p').text();  

but can same kind of selection on variable has not yet been attached dom?

the jquery object take html , make in dom structure further query, can pass in directly create object, or use context if wish query it.

edit: reason seems necessary wrap in div, if not within 1 in example. see jquery object documentation on method further information.

see test framework system at: http://jsfiddle.net/humqu/

var ht = "<body><p>paragraph here</p></body>"; $('<div>' + ht + '</div>').find('p').text(); 

or context:

var ht = "<body><p>paragraph here</p></body>"; $('p', '<div>' + ht + '</div>').text(); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -