Home >Web Front-end >JS Tutorial >How to dynamically load style sheets with JavaScript_javascript tips

How to dynamically load style sheets with JavaScript_javascript tips

WBOY
WBOYOriginal
2016-05-16 16:08:06866browse

The example in this article describes the method of dynamically loading style sheets in JavaScript. Share it with everyone for your reference. The details are as follows:

If we need to change the skin, we can dynamically load the skin's style sheet through JS code. The following code can do it. It is very simple. You only need to make this code into a function and call it dynamically.

var el = document.createElement('link');
el.rel = 'stylesheet';
el.type = 'text/css';
el.href = 'http://www.jb51.net/...' + 'styles.css';
document.body.appendChild(el);

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn