.load () without replacing, just add

2

I need to use .load (), the problem is that it replaces the contents of where I frame it to add what it loaded. I can not create a new div for it to add the loaded content.

Is there any way to specify that it should load into the selected div but not replace what it already has in that div? It loads and adds, does not replace.

I thought of something like $('div').append(function(){ $('div').load('local') but it does not work.

This was meant not to use php include.

    
asked by anonymous 28.01.2016 / 11:39

1 answer

2

You can request the page for AJAX ( $.get() , for example with jQuery) and callback success add it to the page as you like, something similar to this:

$.get('ajax/test.html', function(data){
    $('#result').prepend(data);
});
  

Source: link

To add content without removing what you previously had, you can use:

  • .prepend() : I inserted the content specified by parameter at the beginning of the element set;
  • .append() : I entered the content specified by parameter at the end of the element set;
28.01.2016 / 11:45