0

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");
 }
0

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");
}
  • Thanks, that got rid of the error, but it doesn't seem to be working, but that's a different issue. – AWarnock Sep 25 '15 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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