Creating Style Tag with JavaScript and Adding Rules to It
Sometimes, when working with dynamically created objects on the client, it is needed to style these elements in a specific way. Due to the nature of these objects (for example – unique IDs) , they cannot be styled in the classic way, though. The document.createElement method of JavaScript can be used to create style tags in the head section of the page, however populating it with CSS rules / classes cannot be done with innerHTML under Internet Explorer, which, however has a different method for this particular case – by applying the cssText method to the styleSheet object. Below is an example of how to implement this approach.







