I add a class to the button after an ajax request, so that the button gets a different color. If i click something on the site and go back, than the new class, added by toggleClass, is gone. The Browser shows probably not the changed DOM, but the original from the first page load. Heres my code.
$('.toogleUser').click(function() {
var event_id = $(this).val();
$(this).toggleClass("active");
$.ajax({
url: "/add/",
type: "POST",
data: {
event_id: event_id
},
cache: false
}).done(function(msg) {
$.ambiance({message: msg, type: "success"});
});
});
Edit: the first demo on the jquery doc keeps there class attribute: http://api.jquery.com/toggleClass/ If you highlite a paragraphe, then click on a link and turn back, the paragraphes still keeps the "highlite" class.The code use nothing except toogleClass. Why does my code work not like this from the demo?