Search All Articles Submit your Website or Blog to A New Internet Library
Tuesday, November 3, 2009
Solution: How to change css class for an element in jquery?
In order to change the CSS class applied to an element using jQuery we can use methods like
addClass() and .removeClass()
$("#divId").addClass("classname");
$("#divId").removeClass("classname");
But if we want to change or toggle CSS class between two classes during some events like button click we can use method toggleClass() like below.
Say on click we need to change class from "btn_submit" and "btn_submit_active" or vise versa
if element has class "btn_submit_active" toggle to use "btn_submit". here we use toggleClass() method twise.
$("#divId").toggleClass("btn_submit");
$("#divId").toggleClass("btn_submit_active");
Subscribe to:
Post Comments (Atom)
Also Read other Top Articles
- JSON Serialization in VS 2008
- Implementing Forms Authentication in Silverlight Application.
- Making GridView Rows or Individual Cells Clickable and Selectable.
- Enabling browser back button for GridView Paging and Sorting in Ajax 1.1 and 3.5 (using Visual Studio 2005/ Visual studio 2008)
- How to pass values from User Control to Page or calling Page methods from User Control.
- What is WCF?
- New features in C# 4.0
- C# to VB.NET and VB.NET to C# online free converter tools.


2 comments:
hi.. just dropping by here... have a nice day! http://kantahanan.blogspot.com/
Hi... Looking ways to market your blog? try this: http://bit.ly/instantvisitors
Post a Comment
Post your comments/questions/feedback for this Article.