How to use $.get data to replace certain elements in a webpage?
- by Jack Ha
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
}
);