I have this situation whereby I have managed to remove the necessary class via jquery but when clicking on the same div with the removed class, it still behaves as if the class is not removed.
I have a test situation set up here: http://jsfiddle.net/4L9MK/
<script>
$(document).ready(function(){
$('.next').click(function() {
$(this).removeClass('next');
alert('removed class');
$(this).next().addClass('next');
});
});
</script>
</head>
<body>
<div style="width:500px;" class="siblings">
<ul>ul (parent)
<li>li (sibling)</li>
<li>li (sibling)</li>
<li class="next">li (sibling with class name "next")</li>
<li>li (the next sibling of li with class name "next")</li>
<li>li (sibling)</li>
</ul>
</div>
</body>
Basically if you click the div called
li (sibling with class name "next")
It gives alerts you saying the class 'next' was deleted, then it removes the class 'next' from the current div. However when you click the same div now without the class 'next', the alert still runs even though the class has been removed! Even weirder is that the sibling div which now has class 'next', when clicked, doesn't run the alert.
My question is, how do I ensure that the div with the removed class doesn't alert when clicked and the div with the new class does alert when clicked?
Thanks