Search code examples
jquerytoggleclass

jquery toggleclass to all elements except links


I use jQuery toggleClass like this:

$('.demo').toggleClass('classa classb');

Now how can I toggle this to all elements that have class demo except for links?


Solution

  • Use the not selector:

    $( ".demo" ).not( "a" ).toggleClass( "classa classb" );