JQuery string for DOM without inserting DOM

I have a text box with the following content (innerHTML):

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> </body> </html> 

To prepare the content for parsing the DOM using jQuery, I do the following (temp is just a div):

 $('#temp').append(input.val()); console.log($('#temp').html()); 

As indicated in the jQuery object from the full HTML document , the head, body, html and doctype tags are missing:

 <meta charset="utf-8"> <title></title> 

So is there any other way not to add to the DOM and still get the DOM elements to work? An iframe might be a last resort, but that would be ugly.

+4
source share
1 answer

You could do that.

  $(input.val()).find('your-selector') 

Or you could convey this as a context.

 $('your-selector', $(input.val())) 
+4
source

Source: https://habr.com/ru/post/1343968/


All Articles