santa
santa

Reputation: 12512

Get partial HTML with AJAX

I am trying to get a content of a another page using AJAX call. I am able to get the entire document but is it possible to get a better precision and get only a section that is within a target div?

<div class="myTarget">content that I need</div> 

Here's how I get it now:

$.ajax({
    type: "GET",
    url: "/dir/targetPage",
    dataType: "html",
    success: function(data)
    {
      $('#dropHere').html(data);
    }
}); 

Upvotes: 5

Views: 5985

Answers (1)

Ohgodwhy
Ohgodwhy

Reputation: 50798

$('#dropHere').load('/dir/targetPage #ele');

Where '#ele' is an element with the id of ele and all it's inner children.

Upvotes: 12

Related Questions