Some days ago, i was try to load another page by ajax. I only want certain element to replace my existing element. Due to my site based on WordPress, i think jquery is best option.
So here is my code
$.ajax({ url: "login.html" }).done(function( data ) { var kontener = $('').html(data).find('.kontener'), content = kontener.find('#content'); $('body .kontener').html(content); });
First thing we need to convert the data to jQuery HTML version, by set it as variable for further need as on line
var kontener = $('').html(data).find('.kontener')
So, next we can find the element we want to use
content = kontener.find('#content');
And the last thing we need to do is replace it
$('body .kontener').html(content);
That’s how we get an element from ajax resppons by using jQuery. We can replace existing element with ajax, without loading page.