Native js dynamically add style sheets

 
 

Native js dynamically adds style sheets to html:

 
 
1. Create the tag <style> to add a built-in style sheet
            var style1 = document.createElement('style');
            style1.innerHTML = 'body{color:red}#top:hover{background-color: red;color: white;}';
            document.head.appendChild(style1);
2. The other is to add an external style sheet, that is, add a link node to the document, and then point the href attribute to the URL of the external style sheet
            var link1 = document.createElement('link');
            link1.setAttribute('rel', 'stylesheet');
            link1.setAttribute('type', 'text/css');
            link1.setAttribute('href', 'reset-min.css');
            document.head.appendChild(link1);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325766932&siteId=291194637