1

is it possible to read or extract html/text from a different .html page using jquery?

this what i would like to read and display in a different page

                    <div class="newsItemContent"> 
                      <h1 class="title"> 
                        heading 1
                      </h1>
                      content 1 content 1 content 1 content 1 
                    </div>

                   <div class="newsItemContent"> 
                      <h1 class="title"> 
                        heading 2
                      </h1>
                      content 2 content 2 content 2 content 2 
                    </div>

thanks

5 Answers 5

4

You can extract from another page using the load method thus $('#targetElement').load('page.htm #container') syntax.

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

2 Comments

It causes the page to break all elements (go hidden) and styles to go crazy (page changes color).
Only if the loaded page is not a fragment. It meets the OPs requirement as specified.
2

Most certainly. The $.get() method will do what you want.

Comments

2

If the page is on the same domain/server you could try to access it through AJAX

Comments

1

If the second page is within an iframe, you could access it with something like:

$('#iframeID').contents().html();

Comments

0

Yup you can use ajax for this. Or if it's on a different domain JSONP.

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.