jquery Add and remove elements Class attribute instance code

Source: Internet
Author: User

jquery Add and remove element class attribute instance code: The class property of the element is generally used to set the style, so adding or deleting means changing the style of the element, and here's how to use jquery to delete and add the class attribute value of the element, hoping to help you a bit.
The code example is as follows:

function Switchteachcontrol () {   var target=$ ("#thediv");    if (Target.hasclass ("Controloff"))  {     Target.removeclass ("Controloff");     Target.addclass ("Controlon");   }   Else   {     target.removeclass ("Controlon");     Target.addclass ("Controloff");   

This is a function, this function can detect whether an element exists a specified class property value, and then to add or delete the corresponding operation, here is not more introduced, in particular, can refer to the relevant reading.
Related reading:
1.thehasclass () function can be found in the Hasclass () method section of jquery
The 2.removeClass () function can be found in the Removeclass () method section of jquery .
The 3.addClass () function can be found in the AddClass () method section of jquery .

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=9485

For more information, refer to: http://www.softwhy.com/jquery/

jquery Add and remove elements Class attribute instance code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.