I have an accordion targeting just the anchor element specified by the class “collapseLinks”
and I am trying to exclude a class “vanilla” with the :not() selector. Class “vanila” is just an anchor I would like to behave normally. Right now when you click on the “vanilla” anchor it fires the accordion too. Any help would be great!
$('a.collapseLinks').click(function() {
$("div.slider > a.collapseLinks").click(function() {
$(this).children(".slider > a.collapseLinks").toggle();
});
$(this).toggleClass('collapseLinksClicked');
});
// Stuff to do as soon as the DOM is ready;
$(".internal").hide();
$("input").attr("disabled", "disabled");
$(".slider:not(.vanilla)").click(function() {
$(this).next(".internal:not(.vanilla)").slideToggle();
}).toggle(function() {
$(this).children("span").text("-");
}, function() {
$(this).children("span").text("+");
});
Your first “click” handler is adding a new event handler, every time it is clicked, and these do not override previous handlers. Think carefully about what exactly you are trying to do, and clean up that method. Based on your description, here is a suggestion:
In every version of jQuery since 1.6, the correct way to disable input elements is:
And finally, your second ‘click’ handler is finding ‘slider’ elements (all of which I assume are
<div>elements) and then trying to filter out ‘vanilla’ elements (which I assume to be all<a>elements). Also, no signature of the.toggletakes two functions as arguments.