Say I have the following HTML
<div class="row">
<div class="link grey">
<a href="#">Link</a>
</div>
</div>
<div class="row">
<div class="link">
<a href="#">Link</a>
</div>
</div>
<div class="row">
<div class="link">
<a href="#">Link</a>
</div>
</div>
<div class="row">
<div class="link grey">
<a href="#">Link</a>
</div>
</div>
I want to be able to click the link, have the background colour change and have that state retained on ajax success (ajax call happens when the link is clicked). But right now, on ajax success, the previous sate shows up.
On success, I'm calling the function which handles the event
function ajaxOnSuccess(data) {
$(document).ready(function(){
$('a').on('click', function(){
$(this).closest('.link').toggleClass('grey');
});
});
}
JSFiddle: http://jsfiddle.net/mzg2zk48/