I have a very strange problem. I am using jQuery to intercept a particular tag click.
I have:
<a class="question">lorem ipsum</a>
<a class="question_selected">lorem ipsum</a>
<a class="question">lorem ipsum</a>
<a class="question">lorem ipsum</a>
And my jQuery is:
$("a.question").click(function(){.....});
It should intercept the <a> click where class=”question” but it is also intercepting whenever I click <a class="question_selected">.
What can be the problem?
EDIT:
I am actually changing the classes on click. The tag that I click should become “question_selected” and all other should be “question”. Here is the jQuery: $('a.question_selected').removeClass('question_selected').addClass('question'); $(this).addClass('question_selected').removeClass('question');
Remove the underscore from the class name. Perhaps there’s a bug in jQuery regarding that.
Otherwise, this doesn’t directly answer your question, but some suggestions:
First of all, instead of swapping the class, I’d just use two classes:
Then, in your jQuery, I’d cache your questions:
And then your jquery can be: