Mickael
Mickael

Reputation: 23

How to select element tag from a varible url to jquery load() function

I just have a little question about syntax....

If I want to pass my url in a variable "test" But, I need to select only the data inside the html tag article... what can I do? this doesn't work:

 $(document).ready(function() {
     $('a').click(function(e) {
         e.preventDefault();
         var test = $(this).attr('href');
         $('.window').load(test).find("article"); //this does'nt work, please help
     });
 });

Upvotes: 2

Views: 57

Answers (1)

DarthJDG
DarthJDG

Reputation: 16591

You can pass an optional jQuery selector to the load function (separated by a space from the URL) to load a page fragment.

$(document).ready(function() {
    $('a').click(function(e) {
        e.preventDefault();
        var test = $(this).attr('href');
        $('.window').load(test + ' article');
    });
});

You can find this feature in the jQuery .load() documentation

Upvotes: 2

Related Questions