Variable Visions

Articles jQuery jQuery-Garage-Doors-with-click-target-exclude


tutorials - jQuery and Web-Development.

jQuery Garage Doors with click target exclude

Published Fri. Aug. 03, 2012


Exclude all anchor tags from your jQuery slideToggle function to prevent action before redirect.

While developing my own "garage door" in jQuery, I found that when clicking anchor tags inside the link target the action would start RIGHT before the page redirects to the link.

This line of jQuery will use the .is method and exlude all a tags from the click action.


"When you click on the id box, toggle in a sliding motions the div trigger at a rate of a half second and add the class tabstate2 to tab and also boxstate2 to box."


jQuery('#box').click(function(targetexclude) {
    if( !$(targetexclude.target).is("a") ) {
        jQuery('div.trigger').slideToggle(500);
        jQuery('.tab').toggleClass('tabstate2');
        jQuery('#box').toggleClass('boxstate2');
    }   
});



Tag(s): jQuery, is METHOD, slideToogle, toogleClass