Skip to content

JSL.addStyle()

joesimmons edited this page Sep 25, 2013 · 1 revision

Inserts content into a <style> tag with an optional ID, and adds it to the <head>




Syntax: JSL.addStyle( contentString [, ID] [, parentNode] );


Parameters:

  • contentString: A string to be the content of the <style> element.
  • ID: (optional) An ID to give the element; if omitted, jsl-style- plus a random number from 1 to 999 will be used.
  • parentNode (optional) Append the created <style> element to this element, instead of <head>

Example:

JSL.addStyle('body { color: red; }');

The above code will add this to the <head> element of the page:

<style>body { color: red; }</style>



Note: If you want to pass the parentNode parameter but still want a random ID, just pass a falsy value as the second argument.
Example: JSL.addStyle('body { color: red; }', 0, iframe.head);

Clone this wiki locally