user3301364
user3301364

Reputation:

jQuery append is not working when using load before

Append function is not working when using it after the load function.

$('section article a').on('click',function(e){

    e.preventDefault();
    id = $(this).attr('class');
    $('article[id='+id+']').load( 'articles/'+id+'.html' );

    $('article[id='+id+']').append( "<strong> Where am I?<br/>StackOverflow HELP !!!</strong>" );   //This is NOT appended

});

Any idea ?

Upvotes: 0

Views: 104

Answers (1)

Felix
Felix

Reputation: 38112

Try to wait until your load finish then use append() instead:

$('article[id='+id+']').load( 'articles/'+id+'.html', function() {
    $('article[id='+id+']').append( "<strong> Where am I?<br/>StackOverflow HELP !!!</strong>" ); 
});

Also you can just use $('#'+id) instead of $('article[id='+id+']') since id is unique.

Upvotes: 2

Related Questions