JavaScript's method of dynamically loading style sheets

  • 2020-05-17 04:50:27
  • OfStack

This example demonstrates how JavaScript dynamically loads style sheets. Share with you for your reference. The details are as follows:

If we need to change the skin, we can use the JS code to dynamically load the style sheet of the skin. The following code can do this. It is very simple.


var el = document.createElement('link');
el.rel = 'stylesheet';
el.type = 'text/css';
el.href = '//www.ofstack.com/...' + 'styles.css';
document.body.appendChild(el);

I hope this article is helpful for you to design javascript program.


Related articles: