July 5, 2010

Including JavaScript and CSS in a page (jQuery)

Question by Nimbuz

I recently came across the includeMany jQuery plugin to include external JavaScript and CSS files into a page. Although it was released in early 2009 there are NO references in blogs or elsewhere. I wonder if it’s usable? What is the experience using it?

Answer by Starx

You can include JavaScript and CSS using the example below. There is no need for any plugins.

To include JavaScript code, do this:

$.getScript("youpathtoscript.js",function() {
            //this script is loaded
});

To include CSS files:

$("<link/>", {
   rel: "stylesheet",
   type: "text/css",
   href: "styles/yourcss.css"
}).appendTo("head");

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!