L84
L84

Reputation: 46308

Not a Function After First Click

I have a JS Function that looks like this:

$(function() {
$(".accordion").on("click", "dd", function (event) {
   $("dd.active").find(".content").slideToggle("slow");
   $(this).find(".content").slideToggle("slow");

   var current = event.currentTarget
   if (current.hasClass('active')) {
      current.removeClass('active');
   } 
})
});

The first part works fine, the second part (starting with var current =) works the first time then jQuery throws an error:

TypeError: current.hasClass is not a function
   if (current.hasClass('active')) {

How do I solve this issue?

Here is a jsFiddle.

Upvotes: 1

Views: 51

Answers (1)

Sarath
Sarath

Reputation: 9156

Wrap current reference in jQuery object

   var current = $(event.currentTarget);

jsFiddle.

Upvotes: 1

Related Questions