jQuery Book – Basics through to Performance Optimisations

A few things to note;

  • When using selectors with ID tags, use $(‘#abc’).find(‘.defg .higk’); instead of $(‘#abc .defg .higk’);
  • Also use named functions more-so than anonymous ones;
    var PI = {
    onReady : function() {
    $(‘#magic’).click(PI.candyMtn);
    $(‘#happiness’).load(PI.url + ‘ #unicorns’, PI.unicornCb);
    },
    candyMtn : function(e) {
    $(‘#yayeffects’).slideUp(PI.slideCb);
    },
    slideCb : function() { … },
    unicornCb : function() { … }
    };
    $(document).ready(PI.onReady);
  • Plugin creation;
    // defining the plugin
    (function($){
    $.fn.hoverClass = function(c) {
    return this.hover(
    function() { $(this).toggleClass(c); };
    };
    }(jQuery);// using the plugin
    $(‘li’).hoverClass(‘hover’);
  • see here for signs of poorly written plugins; http://remysharp.com/2010/06/03/signs-of-a-poorly-written-jquery-plugin/
  • See here for details on plugin development; http://www.learningjquery.com/2007/10/a-plugin-development-pattern

http://www.rebeccamurphey.com/jqfundamentals/book/release/html/

jquery-fundamentals-book

CategoriesUI

Leave a Reply