Saturday 5 March 2011

Adding jQuery to your blogger.com

jQuery is one of my favorite frameworks available today. The sheer versatility of the framework is outstanding. So you can expect to see a fair few posts on jQuery throughout this blog. Hopefully you will find them useful - please feel free to ask questions, I will help out if and where I can!


I will dive straight in, with this being the first blog on the site, I may as well make it about my experience with setting up the blog, preparing it for the many posts to come.

Adding jQuery to blogger.com:
  1. Login to your blog. At the top right of the page (for me anyway) click Design 
  2. Click on the Edit HTML tab.
  3. Now search for the line <head>
  4. Now you need to add the jQuery core (I will be using the Google CDN version), after <head> add the following lines - you will notice I am also adding the jQuery UI aswell:
  5. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript">
    <script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js' type='text/javascript'/>
    <link href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/base/jquery-ui.css' rel='stylesheet' type='text/css'/>
    
  6. Next is to add any jQuery code you want to load with EVERY page:
  7. <script type='text/javascript'>
    //<![CDATA[
    $(document).ready(function() {
    
    });
    //]]>
    </script>
    
  8. Now you can place anything you want to run when the blog loads in the normal way. 
For example:
If you wanted to turn all buttons that you place on your blog:
<input type="button" id="myButton" value="This Button" />
Into jQuery UI buttons you could do this:

<script type='text/javascript'>
//<![CDATA[
$(document).ready(function() {
$(":button").button();
});
//]]>
</script>


Note:
The reason for adding the code between:
//<![CDATA[
.....
//]]>
Is that when you submit the code, it stops the code being interpreted, and characters being swapped for their ASCII representation. This isn't really a problem for most browsers, but it makes the code much harder to read next time you fancy changing something!

Scoobler.

Some jQuery books on Amazon.com:

jQuery in Action, Second Edition    jQuery Cookbook: Solutions & Examples for jQuery Developers (Animal Guide)    jQuery: Novice to Ninja

No comments:

Scroll to Top