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 book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

No Reader comments