


Detailed explanation of the steps of js encapsulation operation class
Apr 16, 2018 am 09:40 AMThis time I will bring you a detailed explanation of the steps for jsencapsulation operationclass, what are the precautions for js encapsulation operation class, the following are Let’s take a look at practical cases.
1. Add class
function addClass(ele,cName) { var arr = ele.className.split(' ').concat(cName.split(" ")); for(var i=0;i<arr.length;i++){ for(var k=arr.length-1;k>i;k--){ (arr[k]==="")&&arr.splice(k,1); (arr[i]===arr[k])&&arr.splice(k,1); } } ele.className = arr.join(" "); }
2. Deleteclass
function removeClass(ele,cName) { var arr1 = ele.className.split(' '); var arr2 = cName.split(" "); for(var i=0;i<arr2.length;i++)for(var j=arr1.length-1;j>=0;j--)(arr2[i]===arr1[j])&&arr1.splice(j,1) ele.className = arr1.join(" ") }
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related matters on the php Chinese website article!
Recommended reading:
Detailed explanation of the use of apply and call in JS (with code)
The above is the detailed content of Detailed explanation of the steps of js encapsulation operation class. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PyCharm usage tutorial: guide you in detail to run the operation

What is sudo and why is it important?

Linux Deploy operation steps and precautions

What to do if you forget to press F2 for win10 boot password

Huawei Mate60 Pro screenshot operation steps sharing

Replace the class name of an element using jQuery

Learn to use common PHP built-in objects: master the operation and usage of built-in objects

Discuz domain name modification operation guide
