Aaclass () Encapsulates a common function, classnames property substitution instead of appending an issue

Source: Internet
Author: User

Function styleheaderssiblings () {if (!document.getelementsbytagname)  return false;var  Headers = document.getelementsbytagname ("H1"); for (var i = 0;i <  headers.length; i++) {var elem = getnextelement (headers[i].nextsibling);//elem.style.color  =  "Red";//elem.style.fontsize =  "1.2em";//The following uses the ClassName property, which is a substitution, not an append//elem.classname  =  "Intro";                   //.intro{ color:red;font-size:1.2em;} AddClass (Elem, "Intro");//Call encapsulation function}}//elem.classname += " intro"      note, The first character of the intro is a space, which means that the new CALSS attribute is appended to the original attribute//If there is no attribute in the original, then the classname is directly assigned, without the need to append//So we can encapsulate the above steps into a function for general function  AddClass (Element,value) {if (!element.classname) {element.classname = value;} else{newclassname = element.classname;newclassname +=  "";newclassname += value; Element.cLassname = newclassname;}} 

Aaclass () encapsulates a common function, classnames property substitution instead of appending an issue

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.