tags:

views:

52

answers:

1

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")); // not found, title is outside div#page
     }
  );
+1  A: 

jQuery offers the .load() method for exact that reason.

$('#element_to_insert').load(url + ' #header');
jAndy
thanks, but the load function has the same problems as described above. I have to replace multiple objects, that's why I use $.get
Jack Ha