i have created list of elements. if one element is highlighted (using buttons 'prev' and 'next'), it gets 'active' class. if 'add element' button has been pressed, element gets class 'selected'. but if an active element is selected too, i want to replace 'add button' with 'remove button' - which removes class 'selected' from active element.
here's some code:
if ( $('.active').hasClass('selected') ) {
$('.add').replaceWith('<a href="#" class="add">Usuń zdjęcie</a>');
$('.add').click(function() {
$('.active').removeClass('selected');
return false;
});
}
else {
$('.add').click(function() {
$('.active').addClass('selected');
return false;
});
}
it doesn't work (nothing changes). what's wrong? :|