How to use $.get data to replace certain elements in a webpage?
Posted
by Jack Ha
on Stack Overflow
See other posts from Stack Overflow
or by Jack Ha
Published on 2010-05-28T12:36:29Z
Indexed on
2010/05/28
12:41 UTC
Read the original article
Hit count: 184
I'm using jQuery 1.4.2 to navigate smoothly between similar webpages (in ff3). When clicking on a link, a javascript script should load the new html, filter out the right elements and replace them on the current page.
It looks like the $(htmlcode) does not do the thing I expected. The actions below work when loading the page directly, but when using the $.get I have the following problems:
- the find function seems only to look inside a div element called id="page", which is inside the body element
- one of the elements has
<script>...</script>
, but the<script>...</script>
is not present in the DOM of $(htmlcode).
Anybody knows how to solve this?
$.get(
url,
function(responseText, textStatus, xmlHttpRequest) {
alert($(responseText).find("#header")); // works, #header is inside div#page
alert($(responseText).find("#header").html()); // displays content, but WITHOUT the <script>...</script>
alert($(responseText).find("title")); // does not work, title is outside div#page
}
);
© Stack Overflow or respective owner