Posted By

noah on 05/04/07


Tagged

css toggle DOM simple dhtml boolean easy beginner


Versions (?)

Toggle the className of a DOM element


 / Published in: JavaScript
 

Imagine an element that has two states, represented by two CSS classes named 'expanded' and 'contracted.' This code toggles between the two states in the simplest possible fashion.

  1. el.className = (el.className.indexOf('expanded') != -1) ? el.className.replace(/expanded/,'contracted') : el.className.replace(/contracted/,'expanded');

Report this snippet  

You need to login to post a comment.