jQuery.getCSS

jQuery has a nice jQuery.getScript function that allows you to easily add <script> tags to a webpage.

How can you do the same thing for CSS files? jQuery doesn’t have a built-in jQuery.getCSS / getCSS function, but you can use jQuery('head').append instead. Here’s an example of how to dynamically insert remote CSS and JavaScript for (free) the HTML5 VideoJS player.

jQuery.getCSS

jQuery('head').append('<link rel="stylesheet" rel="nofollow" href="http://vjs.zencdn.net/c/video-js.css" type="text/css" />');

jQuery.getScript('http://vjs.zencdn.net/c/video.js',function()
{
//  you can also set callback items here
//  var myPlayer = _V_("myvideo");
});

It would be nice if there was this sort of function, but there isn’t :\

jQuery.getCSS('http://vjs.zencdn.net/c/video-js.css');

Related Posts:

  • No Related Posts
This entry was posted in Tech Tips, Web Development and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *