jQuery.getCSS

6 Jul

Here is a simple addition to jQuery I got from stackoverflow, and just wanted to share with you. You could use it to get cascading style sheets (CSS) via AJAX and append to DOM . Very similar to jQuery.getScript.

/**
* Get CSS
* @param {Object} $
*/
(function($){
   $.getCSS = function( url, media ){
      $(document.createElement('link') ).attr({
          href: url,
          media: media || 'screen',
          type: 'text/css',
          rel: 'stylesheet'
      }).appendTo('head');
   }
})(jQuery);

//To Use:
jQuery.getCSS("/my/style/file.css") or
jQuery.getCSS("/my/style/file.css", "screen");

6 Responses to “jQuery.getCSS”

  1. matz 09. Jul, 2009 at 5:04 pm #

    well – great great development – overwhelming head start into the continued development and a great & sustainable development.
    i love all what i see.

    BTW can we expect a release in some days / weeks – look forward to it!

    best regards

  2. maze 06. Jul, 2009 at 9:56 pm #

    very good to see your work on Tuiyo. All the news are so sweeet. i am your follower – and i read all the news here and on twitter five t imes a day

  3. Kennnn 06. Jul, 2009 at 3:32 pm #

    Keep em coming dr, are you using this as a base for the stle/template switcher in tuiyo?

  4. mmccoy21 06. Jul, 2009 at 1:14 pm #

    Nice to see some progress, hopefully when I get back from Canada I have a RC to try out!

  5. matze 06. Jul, 2009 at 8:09 am #

    many thanks for the updates – great to hear this news.

    love to see this very fast & sustainable development
    best regards
    matze – keep up the superb project

  6. dr.stonyhills 06. Jul, 2009 at 7:51 am #

    Obviously easy, but just thought i’ll have to start sharing some tips and tricks as i enjoy this hobby of mine!