Use Stylesheets for Changing CSS on Many Elements If you're changing the CSS of more than 20 elements using .css() , consider adding a style tag to the page instead for a nearly 60% increase in speed. The jQuery addClass(), removeClass(), and toggleClass() methods enable you to dynamically add and remove classes on HTML elements. This can be useful when applying multiple style declarations, and it allows you to keep your styles within your style sheet while using jQuery to access them.
Definition and Usage. The toggleClass() method toggles between adding and removing one or more class names from the selected elements. This method checks each element for the specified class names. I’m having an issue in IE 9 (of all things) when using this toggle. I’m using it to toggle a nav and IE 9 actually eats my list items when this script is in place. Anyone had a similar issue or solution? Here’s my markup: Style sheets are managed separately from HTML or any other presentation code for better maintainability. Often need arises to manipulate these class attributes to assign or remove new CSS classes dynamically. jQuery caters this need by providing us methods to inspect and manipulate CSS classes assigned to the HTML elements.