How to use $ .get data to replace certain elements on a web page?

I am using jQuery 1.4.2 to smoothly transition between similar web pages (in ff3). When you click on the link, the javascript script should load a new html, filter out the necessary elements and replace them on the current page.

It seems that $ (htmlcode) is not doing what I expected. The steps below work when loading the page directly, but when using $ .get I have the following problems:

  • The search function seems only to look inside the div element called id = "page", which is located inside the body element
  • one of the elements has <script>...</script>but is <script>...</script>missing in the DOM in $ (htmlcode).

Does anyone know 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
     }
  );
+3
1

jQuery . load() .

$('#element_to_insert').load(url + ' #header');
+1

Source: https://habr.com/ru/post/1747533/


All Articles