HTML5 New properties: How to use the Classlist property

Source: Internet
Author: User

This article brings you the content is about HTML5 new properties: The use of classlist attributes, there is a certain reference value, a friend can refer to the need, I hope you have some help.

The Classlist attribute is added to the HTML5 to implement the class operation with the following API:

Contains (value): Determines whether the class name named value exists Add (value): Add a class name named value Remove (value): Removes the class name named value Toggle (value): If the name value exists , does not exist add

JS Sample code:

Get the node var $test = document.getElementById ("test");//Add a Class$test.classlist.add ("New-class");//Delete a class$ Test.classList.remove ("Old-class");//existence is deleted, does not exist add $test.classlist.toggle ("class");//Determine if it contains $ Test.classList.contains ("class");//Replace Class$test.classlist.remove ("Old-class"); $test. Classlist.add ("New-class") ;
Related Article

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.