javascript jquery add stylesheet if class is present -


can tell me why following doesn't work in 'head'

<script type="text/javascript">  if ($('.company-color').length){     document.write("<link rel='stylesheet' href='company-color.css' type='text/css'>"); }  </script> 

i have class present on pages , want insert above stylesheet page if class '.company-color' present.

use

jquery(function($){     if ($('.company-color').length){         $('body').append("<link rel='stylesheet' href='company-color.css' type='text/css'>"); // or head     } }) 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -