background preloader

YayQuery Podcast - A jQuery Podcast

YayQuery Podcast - A jQuery Podcast

Using Delegate and Undelegate in jQuery 1.4.2 » Learning jQuery As some of you have heard, there have been two new methods added in jQuery 1.4.2, .delegate() and .undelegate(). These methods achieve the same thing as the .live() and .die() methods, they just use a different syntax. For those new to .live(), it's a method in jQuery that allows you to attach events to elements that appear in the document as well as elements that will appear in the future. An example would be if you attached a click event via .live(): JavaScript: $('img.photo').live('click',function(){ lightboxify(this);}); Then appended some photos via ajax later on: // append an image $('body').append('<img src="face.jpg" alt="silly face" class="photo"/>'); The click event would still apply to that new image without having to re-bind the event. Not too long ago, the .live() method was brought up for discussion for a few reasons. and also when you pass any native DOM elements like: // FAILS$(document.body).live('click',function(){}); // WORKS$('ul li').live('click',function(){}) Old way

jQuery 1.4.x’s Greatest Hits: Earle’s Picks - Namoroka Barack Obama had yet to be elected President of the United States, swine flu hadn’t taken hold, and Michael Jackson was still alive … when jQuery 1.3 was released. That sure makes it seem like a long time ago. So it’s no surprise that in that time, the jQuery team concocted a host of great new features and enhancements for the 1.4 release of the library. Now that jQuery 1.4 has been out in the wild for a few months, and we’ve seen the 1.4.1 and 1.4.2 releases, I want to shine a light on the features about which I’m most excited. This isn’t a catalog of everything that’s new in the 1.4.x branch (for that, you should be checking the release notes); rather, it’s a run-down of my favorites: the ones I’ve started using extensively, or the ones that I think show the most promise. Before we delve too deeply, let’s skim over a couple of fun, new (and, some might say, long overdue) API methods. $('p') .slideUp() .delay(2000) .slideDown(); Sweet. Changing Some Fundamentals Event Delegation and Scope

jQuery : codez branché ! | Les intégristes - Namoroka Vous avez toujours voulu être branché ? Non ? Pourquoi tu dis rien ? T’aimes pas les accroches interrogatives Voici donc la suite de notre série d’articles consacrés à jQuery, avec aujourd’hui : le plugin ! La conception de jQuery, centrée sur un même objet, permet d’étendre naturellement notre bibliothèque en créant de nouvelles méthodes. $("p").monplugin(); Nous créerons pour l’exemple un plugin qui fait danser les éléments sélectionnés, appelons-le « jQuery Dance ». On pourra éventuellement lui passer des options : le tempo, et la taille de la piste de danse bien entendu ! Il sera utilisé ainsi : $("p").dance(); Ah, vous l’aviez certainement noté : la sonorité de jQuery est proche de celle de charcuterie. Nommez votre fichier Un plugin doit toujours se nommer ainsi, de manière à ce qu’il soit immédiatement identifiable : jquery.nom_du_plugin.js Notre fichier se nommera donc jquery.dance.js. Isolez votre code (function(){ // Code })() (function($){ // Code })(jQuery) var $j = jQuery.noConflict();

Related: