Search code examples
jqueryajaxjquery-load

jQuery load() multiple elements from same file


Is there an easier way of grabbing elements from the same file without having to load the page a few times?

Currently using this method

$('.side-article-title').load(thisURL+' #item-title');
$(".side-article-subtitle").load(thisURL+' #item-subtitle');
$(".side-article-detail").load(thisURL+' #item-detail');

Solution

  • //Load data
    var temp = $('<div/>');
    temp.load(thisURL);
    
    //Display data
    $('.side-article-title').html($('#item-title',temp));
    $(".side-article-subtitle").html($('#item-subtitle',temp));
    $(".side-article-detail").html($('#item-detail',temp));