Use JavaScript's classlist instead of JQuery's class operation

Source: Internet
Author: User
Tags jquery addclass

JavaScript's classname operation method is uncomfortable, he gets a continuous string

Must be split apart with split, so many people want to use jquery Addclass,removeclass,hasclass and so on.

Classlist solves this problem, although compatibility is not good. But it's going to be better, let's learn first.

HtmlElement will have classlist properties,

The main methods are as follows:

El.classList.add ()

El.classList.remove ()

El.classList.contain ()

El.classList.toggle ()

Try it out, it's easy, it's going to be a lot less dependent on jquery. La La la

Use JavaScript's classlist instead of JQuery's class operation

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.