Use mootools to dynamically add CSS style sheet code, compatible with various browsers

Source: Internet
Author: User
Tags mootools

But this is not conducive to plug-in transplantation, so I wrote this function to dynamically generate CSS. CopyCodeThe Code is as follows: addcss = function (c ){
VaR sty = Document. createelement ('style ');
Sty. type = 'text/CSS ';
If (browser. ie ){
Sty.stylesheet.css text = C;
} Else {
VaR frag = Document. createdocumentfragment ();
Frag. appendchild (document. createtextnode (c ));
Sty. appendchild (frag );
}
Document. getelementsbytagname ('head') [0]. appendchild (STY );
};
Addcss ('a {background-color: red; color: black; padding: 20px ;}');

As shown above, the Code is a simple function. You can directly add code using addcss when necessary.
Note: I have tested this function in IE6, 7, 8, 9, and Firefox.

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.