Thinking of adding JS API to HTML5

Source: Internet
Author: User

1. Why the variable name of JavaScript does not use the naming method in CSS, and the choice of using the Hump naming method

Because "-" in JavaScript means subtraction, an unnecessary problem arises if you use "-".


2. There is already a ClassName method in JavaScript to add the class name, why do you want to add a new Classlist.add method

Because Classlist provides the ability to judge DOM element types, string processing, regular expression matching and classname functionality is not perfect.

P.classlist.length; Gets the number of class names in the P element
P.classlist.item (1); Gets the class name of index 1 in the P element
P.classlist.add ("big"); Add the big class to the P element
P.classlist.remove ("big"); To remove the big class from the P element
P.classlist.contains ("big"); Determine if the P element contains a class called Big
P.classlist.toggle ("big"); If the big class exists in the P element, it is deleted, and if the big class does not exist in the P element, the big class is added to P


Disadvantages of Classlist
Only a single class name can be manipulated, and if the class name argument in the Add,remove,contains,toggle method contains a space, the method call will error


3. In JS, you can customize the Add attribute why do you have to have data to add custom properties, what is the difference between them.
Easy to manage

Thinking of adding JS API to HTML5

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.