silly quick question:
I have my:
$('#result').load('ajax/test.html');
but what if I don't want to insert my loaded content into #result, but prepend it to #result, maintaining all precedent elements? Is it possible to create a variable, load it with content and then append or prepend it to my #result? I imagine some other scenarios where with my brand new variable I can manipulate it before inserting it into the DOM.
jQuery append() MethodThe append() method inserts specified content at the end of the selected elements. Tip: To insert content at the beginning of the selected elements, use the prepend() method.
In jQuery, the append() method is used to insert specified content as the last child (at the end of) the selected elements in the jQuery collection.
click(function() { if(pageNum <= max) { $. get(nextLink + ' article', function(data) { $('#content'). append(data); }); } }); If filtering specific elements with load(), you will have to do that yourself.
The jQuery load() method is a simple, but powerful AJAX method. The load() method loads data from a server and puts the returned data into the selected element.
You mean something like this?
var content; $.get('ajax/test.html', function(data){ content= data; $('#result').prepend(content); });
That saves your loaded content into a variable first and you can manipulate it however you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With