jQuery add stylesheet if not loaded

Sam Deering

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

var cssUrl = 'css/style.css';
    $("head").append('<link rel="stylesheet" type="text/css" href="'+cssUrl+'"/>');

Free JavaScript: Novice to Ninja Sample

Get a free 32-page chapter of JavaScript: Novice to Ninja and receive updates on exclusive offers from SitePoint.

No Reader comments