ngplayground
ngplayground

Reputation: 21627

jQuery efficiently load multiple divs with one .get() call

$.get('text.php', {}, function(data) {
    var $response = $('<div />').html(data);
    var $jeremy= $response.find('#jeremy')
    var $kyle = $response.find('#kyle');
    $('#right').append($jeremy).append($kyle);
},'html');

Would the above be the most efficient and DRY method of calling in multiple div's with one ajax call?

Upvotes: 0

Views: 350

Answers (1)

Mardie
Mardie

Reputation: 1672

More efficient and less DRY but less readable too:

$.get('text.php', {}, function(data) {
    $('#right').append( $('<div />').html(data).find('#jeremy, #kyle') );
},'html');

Upvotes: 1

Related Questions