0

I am using jquery to get the data from one web page and show it in another page. Basically, I have a string that includes the html code of the page such as:

var str = '<head><title>some title</title><head><body><div class="main"><div id="inner"></div></div></body>';

and I need to get the content of "#inner" from str. How to is this possible? I am looking for some solution that is fast, short and without using a lot of memory.

2 Answers 2

1

jQuery allows you to build HTML from strings, so you can just find the element within:

var str = '<head><title>some title</title><head><body><div class="main"><div id="inner"></div></div></body>';
$(str).find('#inner');

This works as long as you're looking for DOM elements. This will not handle the <head/> of the document.

Sign up to request clarification or add additional context in comments.

Comments

0

You can build HTML Elements from strings..

var str = '<head><title>some title</title><head><body><div class="main"><div id="inner"></div></div></body>';
var a = $(str);
var _innerHTML = a.find("#inner").html();

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.