Web development javascript Loading CSS File

Source: Internet
Author: User

Under normal circumstances, the browser load CSS file generally has 3 sources

(1) The browser default comes with

(2) Loading in the head file of the Web page

(3) Insert in page code

Today, we're going to be able to load CSS files with JavaScript.

Add code below

var fileref = document.createelement (' link '); Fileref.setattribute (' rel ', ' stylesheet '); Fileref.setattribute (' type ') , ' text/css '); Fileref.setattribute (' href ', ' css file path ');d ocument.getelementsbytagname (' head ') [0].appendchild ( FILEREF);

Actual in the browser kernel code in the JavaScript and CSS inside the implementation is originally belong to the C + + level, at the bottom of the call can be made to each other, so from the theoretical level calls the problem is not big.



Contact information

qq:390012381

:d Onghuitalk

Reprint Please specify source: http://blog.csdn.net/lihui130135


Web development javascript Loading CSS File

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.