Some small attempts at native JS

Source: Internet
Author: User

Intent to mimic JQ operation and get a personal toolbox, constantly improve the code are personal groping, so there will certainly be a lot of deficiencies, I hope readers can put forward.

1 varXzhutils = {2   //Add a class-----DOM object-----3   //[email protected]: obj DOM object4   //[email protected]: CLS-Added classes5AddClass:function(obj, cls) {6     varOcls =Obj.classname;7     if(!ocls) {8Obj.classname =CLS;9}Else{TenOcls + = "" +CLS; OneObj.classname =Ocls; A     } -   }, -   //-----Remove a class from a DOM object----- the   //[email protected]: obj DOM object -   //[email protected]: CLS-Removed classes -Removeclass:function(obj, cls) { -     varOcls =Obj.classname; +     if(ocls) { -       vararr = Ocls.split (""); +        for(varIincharr) { A         if(arr[i]==CLS) { atArr.splice (i,1); -            Break; -         } -       } -Ocls = Arr.join (""); -Obj.classname =Ocls; in     } -   }, to   //-----Calculate The roll-up value----- +Scrollpos:function() { -     varScrollpos; the     if(typeofWindow.pageyoffset! = ' undefined '){  *Scrollpos =Window.pageyoffset; $}Else if(typeofDocument.compatmode! = ' undefined ' && document.compatmode! = ' Backcompat '){ Panax NotoginsengScrollpos =Document.documentElement.scrollTop; -}Else if(typeofDocument.body! = ' undefined '){  theScrollpos =Document.body.scrollTop; +     } A     returnScrollpos; the   }, +   //-----Get the next sibling node----- -   //[email protected]: EVENTOBJ DOM object to get the next sibling node $   //[Email protected]: X eventobj's next sibling node $Next:function(EVENTOBJ) { -     varE =EVENTOBJ; -     varx =e.nextsibling; the      while(x.nodetype!=1){ -x =x.nextsibling;Wuyi     } the     returnx; -   } Wu}

Some small attempts at native JS

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: 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.