use .get() to get html of a div in another page

2019-08-28 16:13发布

问题:

<script>
    $.get("link.html", function(data) {
      var data = $(data);
      //do something
      $("#Container").html(data);
    })
<script>

how can i get html of a div from another page to current page? i used jquery load method but the scripts didn't executed.

sorry for bad English!

回答1:

try:

$.get("link.html", function(data) {
    var html = $('<div>').html(data);
    var content = html.find("div#some_div_id").html();
    //do something
    $("#Container").html(content);
});

or you could use .load(), like

$('#Container').load('link.html #some_div_id');


回答2:

Did you try this?

$("#Container").load("link.html");


标签: jquery get load