दस्तावेज़ में शैली तत्व जोड़ने से पहले नियम जोड़ सकते हैं।
पुराने आईई ब्राउज़रों notes- एक जोड़े को एक शैली तत्व के लिए बच्चे नोड्स नहीं जोड़ है, तो उनके लिए तत्व के styleSheet.csstext संपत्ति के लिए प्रदान कर सकते हैं। सुनिश्चित करें कि आप दस्तावेज़ के शीर्ष पर नया तत्व जोड़ दें। इसके बाद यहां
document.head.appendChild(document.createElement("style")).setAttribute("type", "text/css");
var mycss = document.styleSheets[document.styleSheets.length-1];
है:
function addStyle(css, media1, title1){
var el= document.createElement('style');
el.type= 'text/css';
if(media1) el.media= media1;
if(title1) el.title= title1;
if(el.styleSheet) el.styleSheet.cssText= css;//IE
else{
el.appendChild(document.createTextNode(css));
}
//return el without the next line if you want to append it later
return document.getElementsByTagName('head')[0].appendChild(el);
}
var cs1= [
'#yw_psq, #yw_psq h2{background-color: green; color: white;}',
'#yw_psq_div{margin: 1ex; position: relative; text-align: center;}',
'#ps_counter{color: white; margin: 1ex 0 0 0; text-align: center;}',
'#pzsq_grid button{cursor: pointer; font-size: 1.2em; width: 100%;}',
'#delaySpan{font-weight: bold; margin-left: 1em;}'
]
addStyle(cs1.join('\n'),'screen','yw_psq');
यहाँ आप इस सवाल का जवाब है: [http://stackoverflow.com/questions/524696/how-to-create-a-style-tag-with-javascript][1] [ 1]: http://stackoverflow.com/questions/524696/how-to-create-a-style-tag-with-javascript – netadictos
धन्यवाद netadictos, लेकिन विषय थोड़ा अलग है –
मुझे लगता है कि आप दस्तावेज़ को क्लोन कर सकते हैं क्लोन से शैली-चादरें और नया जोड़ें और ऑब्जेक्ट प्राप्त करें और दस्तावेज़ क्लोन को फिर से हटा दें। – noob