javascript beginner: add a dynamic style in javascript? [duplicate]
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How to create a <style> tag with Javascript I write a dynamic form using java-script. I want to add the style in java-script itself. I write some code to add a style. But it is not working.This is the code am write in my project. var sheet = document.createElement('style'); sheet.type="text/css"; sheet.innerHTML = "body{color:red;}"; document.body.appendChild(sheet); Anyone help me please. 回答1: Your code is fine