JavaScript
Article

jQuery add stylesheet if not loaded

By Sam Deering

Code snippet quicky. Use jQuery to add a setylesheet if it’s not already loaded.

var cssUrl = 'css/style.css';
if($('link[rel*=style][href="'+cssUrl+'"]').length==0)
{
    $("head").append('');
}

No Reader comments

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.