esafwan
esafwan

Reputation: 18029

Ajaxify links with a particular class using jquery

Is it possible to load all the links with class 'ajax' without refreshing the page? The complete body content should be changed, the page title and the url should so it can be bookmarked.

Upvotes: 1

Views: 1276

Answers (2)

Dunhamzzz
Dunhamzzz

Reputation: 14808

This should work for all links with a certain class, 'target' is the id of your main content div. It requires no editing of your current mark up.

$('.class').click(function(e) {
    e.preventDefault();
    $('#target').load($(this).attr('href'));
});

Upvotes: 2

rickyduck
rickyduck

Reputation: 4084

$('a.blah').click(function(e){
    e.preventDefault;
    $.get('page.html', function(data){
        $('body').html(data);
    });
});

That is probably the simplest way, replace blah with your class, and page.html with your page.

Upvotes: 3

Related Questions