1

I'm trying to get a script to work, I got it working in a JSFiddle. I keep getting a TypeError and I'm not sure what's going on. The script is below.

Yes, jQuery and jQuery noConflict are being loaded before this.

 jQuery(".icon").onclick(
 function(){
  var tab = jQuery(this).attr("data-tab");
     if( jQuery(".visible").attr("data-tab") != tab ){
          jQuery(".visible").removeClass("visible");
                                                }
     jQuery(".content[data-tab='" + tab + "']").toggleClass("visible");
 }

1 Answer 1

1

onclick is not a jQuery function. You need to use .on('click', function() {....:

jQuery(".icon").on('click', function() {

    var tab = jQuery(this).attr("data-tab");

    if (jQuery(".visible").attr("data-tab") != tab) 
    {
        jQuery(".visible").removeClass("visible");
    }

    jQuery(".content[data-tab='" + tab + "']").toggleClass("visible");
}
1
  • Thanks, that got rid of the error, but it doesn't seem to be working, but that's a different issue.
    – AWarnock
    Sep 25, 2015 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.