How to get the html of a div on another page with jQuery ajax?

前端 未结 5 1089
忘掉有多难
忘掉有多难 2020-11-27 12:30

I\'m using jQuery\'s ajax code to load new pages, but wanted him to get only the html of a div.

My codes: HTML:


    
5条回答
  •  失恋的感觉
    2020-11-27 13:09

    $.ajax({
      url:href,
      type:'get',
      success: function(data){
       console.log($(data)); 
      }
    });
    

    This console log gets an array like object: [meta, title, ,], very strange

    You can use JavaScript:

    var doc = document.documentElement.cloneNode()
    doc.innerHTML = data
    $content = $(doc.querySelector('#content'))
    

提交回复
热议问题