Adding CSS to a page through Javascript

Categories: css, Javascript

There is no sensible reason to use this but it comes in handy as a hack for CMS systems - when there is no other choice!.

var head = document.getElementsByTagName('head')[0], 
style = document.createElement('style'),
rules = document.createTextNode('.coming-soon-state-selection{margin:25px 0;}.coming-soon-table{width:593px;}.coming-soon-table .title{overflow:hidden;}.coming-soon-table .title h3{float:left;font-size:1.375rem;}.coming-soon-table .title p{float:right;line-height:2rem;padding-left:22px;}.coming-soon-table .coming-soon-state{border-bottom:1px solid #dbdbdb;}.coming-soon-table .coming-soon-state .category .category-title{min-height:40px;border-top:1px solid #dbdbdb;border-bottom:1px dotted #ababab;overflow:hidden;}');
style.type = 'text/css';
if (style.styleSheet) {
style.styleSheet.cssText = rules.nodeValue;
} else {
style.appendChild(rules);
}
head.appendChild(style);

8 Comments

  • 20150408xujianhong said

    <H1><a href="http://www.fitflop.us.com"><strong>fitflops outlet</strong></a></H1>
    <a href="http://www.coachoutletstoreonline.eu.com"><strong>coach outlet</strong></a>
    [url=http://www.louis-vuittonoutlet.us.org][b]louis vuitton handbags[/b][/url]
    http://www.nike-outletstores.com

  • Yaojia said

    <H1><a href="http://seattleseahawks.jerseyscheap.us.com" title="seahawks jersey"><strong>seahawks jersey</strong></a></H1>
    <a href="http://www.moncleroutletstore.us.org" title="moncler jackets"><strong>moncler jackets</strong></a>
    <H1><a href="http://chicagobears.jerseyscheap.us.com"><strong>chicago bears jerseys</strong></a></H1>
    <a href="http://www.raybans-sunglasses.us.org"><strong>ray ban sunglasses</strong></a>
    [url=http://www.montblancpensoutlet.name][b]mont blanc pens[/b][/url]
    [url=http://www.raybans-sunglasses.us.org]cheap ray bans[/url]
    http://www.nikeairhuarache.com.co

  • Buy custom Essay said

    Javascript is recently the customer side scripting dialect, which is utilized to associate with the client in HTML site pages. Along these lines, don't stress over it, it was only a coding dialect.

  • website explainer video to explain said

    Javascript is a scripted programming dialect normally used to add intuitiveness to website pages. With just HTML and CSS, you can just set a depiction for how the site page looks, however utilizing Javascript, you can add a small program to the page that can make it progressively do stuff. For example, you could flip through a slideshow of pictures, or show a clock, or put a Chess amusement on the page, or something to that effect.

  • Explainer Video Production said

    By rolling out one improvement to your site's CSS template, you can consequently make it to each page of your site. The greater your site, the additional time CSS spares you. What's more, not exclusively does CSS spare time, it additionally guarantees that your pages have steady styling all through your site.

Add a Comment