Posts

Showing posts from November, 2011

Handling CSS with JQuery

1. Modify class at runtime 1.1. If an element has multiple classes attached and you need to remove one of class (say 'oldclass') $(selector).removeClass("oldclass") 1.2. If you want to add a new class to an element (say 'newclass') $(selector).addClass('newclass') 1.3. If you want to replace one of the class associated with element (say replace 'oldclass' with 'newclass') $(selector).removeClass('oldclass').addclass('newclass') 1.4. If you want to replace all classes with a different class $(selector).attr('class','newclass') // with this one 2. Notes on using multiple classes. 2.1. If you want to specify multiple classes to an element, separate them with space. <div class="class1 class2 class3"></div> OR $('div').addClass('classA classB') OR $('div').addClass('classA').addClass('classB') 2.2. More than the sequence in which classes are spe...