Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the html of a div from a different page with AJAX?

How can I get the html of a certain html element which is located on a different site?

Solution:

$.ajax({
url: 'somefile.html',
success: function(data) {
    data=$(data).find('div#id');
    $('#mydiv').html(data);
    alert('Done.');
 }
});
like image 859
Mike Burnwood Avatar asked Jun 13 '12 20:06

Mike Burnwood


2 Answers

You can use $.load with an appended container

The .load() method, unlike $.get(), allows us to specify a portion of the remote document to be inserted.

$('#result').load('ajax/test.html #container');
like image 63
Norse Avatar answered Sep 20 '22 20:09

Norse


Make a ajax call to a php or any other file , use CURL or other tools to grab the page you want and extract the div and echo it and then when you get back the html just put it inside a div in your page

    $.ajax({
    url: 'somefile.html',
    success: function(data) {
                    data=$(data).find('div#id');
        $('#mydiv').html(data);
        alert('Done.');
     }
    });
like image 21
user1415567 Avatar answered Sep 18 '22 20:09

user1415567