SlideShare une entreprise Scribd logo
1  sur  15
10 Time-Savers You (Maybe) Don't Know




           Girish Gangadharan


@appoosa        girish@giri.sh      http://giri.sh
Limit DOM traversal

var $items = $(„#products‟);

$items.click(function() {
          $(this).next(„div‟).slideToggle();
});

$items.addClass(„active‟);

$items.closest(„p#category‟).animate({ height:100px });
Less code. Better readability.

var $userprofile = $(„#user-profile‟);
$userprofile
     .hover(function () {
                 $(this).addClass(“highlight");
            },
            function () {
                 $(this).removeClass(“highlight");
      })
     .click(function() {
          //do something
     })
     .fadeIn(„slow‟);
Don‟t leave them hanging.


    :first-child, :last-child, :even, :odd, :parent, :next, :prev, etc.



Precede them with a tag name or some selector;
      else the universal selector is implied.

                     $(':focus') = $('*:focus')
Understand what each does. Use appropriately.

         $('#sometable').each(function(){
                $('td', this).bind('hover', function(){
                      $(this).toggleClass('hover');
                });
          });
         $('#sometable').each(function(){
                $('td', this).live('hover', function(){
                      $(this).toggleClass('hover');
                });
          });
         $('#sometable').delegate('td', 'hover', function(){
                $(this).toggleClass('hover');
         });
Create in memory. Then update the DOM.

var $mylist = $('#mylist'); // <ul>
for (var i = 0; i < 100; i++) {
           $mylist.append('<li>' + bestsellers[i] + '</li>');
}



var $mylist = $('#mylist'); // <ul>
var concatenatedList = “”;
for (var i = 0; i < 100; i++) {
          concatenatedList += ('<li>' + bestsellers[i] + '</li>');
}
$mylist.append(concatenatedList);
Bind less.


$(„#reports td‟).bind(„click‟, function() {
      //do something
})




$(„#reports‟).bind(„click‟, function(e) {
     var target = e.target;
     if (target.nodeName === „td') {
                // do something
     }
})
Choose your event carefully.


$(document).ready(function() {
     //Fires as soon as the DOM is ready
     //Doesn‟t wait for images, style sheets etc.
})


$(window).load(function() {
     //Fires after all the content is loaded
     //Includes images, style sheets, etc.
})
Think right-to-left (except for IDs)



 $('#user-profiles > li > input:disabled');




$('#user-profiles‟).find(„li > input:disabled');
Sizzle engine is highly optimized but…

var $someElement = $(„#elementId‟);
                 Vs.
var someElement = document.getElementById(„elementId‟);



                 $(„#elementId‟).css(„display‟, „block‟);
                                      Vs.
                 document.getElementById(„elementId‟).style.display = „block‟;


             Do you really need a whole library to
                   accomplish your tasks?
Will this improve page performance by x times?

                        Probably, not.
(especially if you don‟t have a complex multi-nested DOM)




       For example, how to better structure your code.
           • Module Pattern
           • Revealing Module Pattern
           • Constructional Pattern
           • Creational Pattern
           • Factory Pattern
           • etc.
Essential JavaScript Design Patterns: (Free!)
http://addyosmani.com/blog/essentialjsdesignpatternsupdate1


jQuery: Novice to Ninja
http://www.amazon.com/jQuery-Novice-Ninja-Earle-Castledine/dp/0980576857



                            jQuery API
                            http://api.jquery.com



                            JavaScript Performance Testing
                            http://jsperf.com/browse
10 Time-Savers You (Maybe) Don't Know




           Girish Gangadharan


@appoosa        girish@giri.sh      http://giri.sh

Contenu connexe

Tendances

jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009Remy Sharp
 
Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Jack Franklin
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
How to learn j query
How to learn j queryHow to learn j query
How to learn j queryBaoyu Xu
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do MoreRemy Sharp
 
jQuery Foot-Gun Features
jQuery Foot-Gun FeaturesjQuery Foot-Gun Features
jQuery Foot-Gun Featuresdmethvin
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tCosimo Streppone
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgetsvelveeta_512
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web frameworktaggg
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Dotan Dimet
 

Tendances (20)

jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
How to learn j query
How to learn j queryHow to learn j query
How to learn j query
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
jQuery Foot-Gun Features
jQuery Foot-Gun FeaturesjQuery Foot-Gun Features
jQuery Foot-Gun Features
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn't
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgets
 
Jquery
JqueryJquery
Jquery
 
Intro to jquery
Intro to jqueryIntro to jquery
Intro to jquery
 
J queryui
J queryuiJ queryui
J queryui
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
 
Jquery introduction
Jquery introductionJquery introduction
Jquery introduction
 
Mojolicious on Steroids
Mojolicious on SteroidsMojolicious on Steroids
Mojolicious on Steroids
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
 
Jquery-overview
Jquery-overviewJquery-overview
Jquery-overview
 

En vedette

Presentación Gonzalo Cubillos
Presentación Gonzalo CubillosPresentación Gonzalo Cubillos
Presentación Gonzalo CubillosVisnja Tomicic
 
Ghanshyam Asked To Krishna
Ghanshyam Asked To KrishnaGhanshyam Asked To Krishna
Ghanshyam Asked To KrishnaKapil Chawla
 
Building your-personal-brand-ver-0-7
Building your-personal-brand-ver-0-7Building your-personal-brand-ver-0-7
Building your-personal-brand-ver-0-7Aryandra Anantama
 
#Ti2016 Tijuana Innovadora 2016, Creativa
#Ti2016 Tijuana Innovadora 2016, Creativa#Ti2016 Tijuana Innovadora 2016, Creativa
#Ti2016 Tijuana Innovadora 2016, CreativaClaudia Basurto
 
Le collectif du 4 Décembre écrit au pouvoir législatif
Le collectif du 4 Décembre écrit au pouvoir législatifLe collectif du 4 Décembre écrit au pouvoir législatif
Le collectif du 4 Décembre écrit au pouvoir législatifRadio Télévision Caraibes
 
Socializacion del proyecto de educatic martha reyes
Socializacion del proyecto de educatic martha reyesSocializacion del proyecto de educatic martha reyes
Socializacion del proyecto de educatic martha reyesMCREYESH1965
 
Taking Away The Keys
Taking Away The KeysTaking Away The Keys
Taking Away The KeysLaurenwatral
 
Learning Analytics at KULeuven by the team of Erik Duval
Learning Analytics at KULeuven by the team of Erik DuvalLearning Analytics at KULeuven by the team of Erik Duval
Learning Analytics at KULeuven by the team of Erik DuvalSten Govaerts
 
Présentation Schéma Directeur Open Source au S2LQ 2015
Présentation Schéma Directeur Open Source au S2LQ 2015Présentation Schéma Directeur Open Source au S2LQ 2015
Présentation Schéma Directeur Open Source au S2LQ 2015Michel-Marie Maudet
 
El nazismo breve resumen
El nazismo breve resumenEl nazismo breve resumen
El nazismo breve resumenLiseth Mejia
 
Safety with a Star (DE)
Safety with a Star (DE)Safety with a Star (DE)
Safety with a Star (DE)XSPlatforms
 

En vedette (13)

Presentación Gonzalo Cubillos
Presentación Gonzalo CubillosPresentación Gonzalo Cubillos
Presentación Gonzalo Cubillos
 
Ghanshyam Asked To Krishna
Ghanshyam Asked To KrishnaGhanshyam Asked To Krishna
Ghanshyam Asked To Krishna
 
Building your-personal-brand-ver-0-7
Building your-personal-brand-ver-0-7Building your-personal-brand-ver-0-7
Building your-personal-brand-ver-0-7
 
#Ti2016 Tijuana Innovadora 2016, Creativa
#Ti2016 Tijuana Innovadora 2016, Creativa#Ti2016 Tijuana Innovadora 2016, Creativa
#Ti2016 Tijuana Innovadora 2016, Creativa
 
Le collectif du 4 Décembre écrit au pouvoir législatif
Le collectif du 4 Décembre écrit au pouvoir législatifLe collectif du 4 Décembre écrit au pouvoir législatif
Le collectif du 4 Décembre écrit au pouvoir législatif
 
Socializacion del proyecto de educatic martha reyes
Socializacion del proyecto de educatic martha reyesSocializacion del proyecto de educatic martha reyes
Socializacion del proyecto de educatic martha reyes
 
Taking Away The Keys
Taking Away The KeysTaking Away The Keys
Taking Away The Keys
 
Learning Analytics at KULeuven by the team of Erik Duval
Learning Analytics at KULeuven by the team of Erik DuvalLearning Analytics at KULeuven by the team of Erik Duval
Learning Analytics at KULeuven by the team of Erik Duval
 
C.Harris
C.HarrisC.Harris
C.Harris
 
Présentation Schéma Directeur Open Source au S2LQ 2015
Présentation Schéma Directeur Open Source au S2LQ 2015Présentation Schéma Directeur Open Source au S2LQ 2015
Présentation Schéma Directeur Open Source au S2LQ 2015
 
El nazismo breve resumen
El nazismo breve resumenEl nazismo breve resumen
El nazismo breve resumen
 
Safety with a Star (DE)
Safety with a Star (DE)Safety with a Star (DE)
Safety with a Star (DE)
 
Mayra ,,,,,,,,
Mayra ,,,,,,,,Mayra ,,,,,,,,
Mayra ,,,,,,,,
 

Similaire à jQuery - 10 Time-Savers You (Maybe) Don't Know

Jquery optimization-tips
Jquery optimization-tipsJquery optimization-tips
Jquery optimization-tipsanubavam-techkt
 
jQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformancejQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformanceJonas De Smet
 
Using jQuery to Extend CSS
Using jQuery to Extend CSSUsing jQuery to Extend CSS
Using jQuery to Extend CSSChris Coyier
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsJarod Ferguson
 
Advanced jQuery
Advanced jQueryAdvanced jQuery
Advanced jQuerysergioafp
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptjQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptGuy Royse
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup PerformanceJustin Cataldo
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
06 jQuery #burningkeyboards
06 jQuery  #burningkeyboards06 jQuery  #burningkeyboards
06 jQuery #burningkeyboardsDenis Ristic
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the newRemy Sharp
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Thinqloud
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScriptAndrew Dupont
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentationMevin Mohan
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryRemy Sharp
 
Jquery Best Practices
Jquery Best PracticesJquery Best Practices
Jquery Best Practicesbrinsknaps
 
Javascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularJavascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularErik Guzman
 

Similaire à jQuery - 10 Time-Savers You (Maybe) Don't Know (20)

Jquery optimization-tips
Jquery optimization-tipsJquery optimization-tips
Jquery optimization-tips
 
jQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformancejQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and Performance
 
Using jQuery to Extend CSS
Using jQuery to Extend CSSUsing jQuery to Extend CSS
Using jQuery to Extend CSS
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
Advanced jQuery
Advanced jQueryAdvanced jQuery
Advanced jQuery
 
jQuery
jQueryjQuery
jQuery
 
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScriptjQuery & 10,000 Global Functions: Working with Legacy JavaScript
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
06 jQuery #burningkeyboards
06 jQuery  #burningkeyboards06 jQuery  #burningkeyboards
06 jQuery #burningkeyboards
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
 
J query1
J query1J query1
J query1
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
 
J query training
J query trainingJ query training
J query training
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
 
Jquery Best Practices
Jquery Best PracticesJquery Best Practices
Jquery Best Practices
 
Javascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularJavascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & Angular
 

Plus de girish82

Introduction to node
Introduction to nodeIntroduction to node
Introduction to nodegirish82
 
Designing better-ux
Designing better-uxDesigning better-ux
Designing better-uxgirish82
 
Designing better-ux-workshop-2
Designing better-ux-workshop-2Designing better-ux-workshop-2
Designing better-ux-workshop-2girish82
 
Designing better-ux-workshop-3
Designing better-ux-workshop-3Designing better-ux-workshop-3
Designing better-ux-workshop-3girish82
 
Designing better-ux-workshop-4
Designing better-ux-workshop-4Designing better-ux-workshop-4
Designing better-ux-workshop-4girish82
 
Designing better-ux-workshop-5
Designing better-ux-workshop-5Designing better-ux-workshop-5
Designing better-ux-workshop-5girish82
 
Why we need to hire UX professionals
Why we need to hire UX professionalsWhy we need to hire UX professionals
Why we need to hire UX professionalsgirish82
 
jQuery - Doing it right
jQuery - Doing it rightjQuery - Doing it right
jQuery - Doing it rightgirish82
 

Plus de girish82 (8)

Introduction to node
Introduction to nodeIntroduction to node
Introduction to node
 
Designing better-ux
Designing better-uxDesigning better-ux
Designing better-ux
 
Designing better-ux-workshop-2
Designing better-ux-workshop-2Designing better-ux-workshop-2
Designing better-ux-workshop-2
 
Designing better-ux-workshop-3
Designing better-ux-workshop-3Designing better-ux-workshop-3
Designing better-ux-workshop-3
 
Designing better-ux-workshop-4
Designing better-ux-workshop-4Designing better-ux-workshop-4
Designing better-ux-workshop-4
 
Designing better-ux-workshop-5
Designing better-ux-workshop-5Designing better-ux-workshop-5
Designing better-ux-workshop-5
 
Why we need to hire UX professionals
Why we need to hire UX professionalsWhy we need to hire UX professionals
Why we need to hire UX professionals
 
jQuery - Doing it right
jQuery - Doing it rightjQuery - Doing it right
jQuery - Doing it right
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Dernier (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

jQuery - 10 Time-Savers You (Maybe) Don't Know

  • 1. 10 Time-Savers You (Maybe) Don't Know Girish Gangadharan @appoosa girish@giri.sh http://giri.sh
  • 2. Limit DOM traversal var $items = $(„#products‟); $items.click(function() { $(this).next(„div‟).slideToggle(); }); $items.addClass(„active‟); $items.closest(„p#category‟).animate({ height:100px });
  • 3. Less code. Better readability. var $userprofile = $(„#user-profile‟); $userprofile .hover(function () { $(this).addClass(“highlight"); }, function () { $(this).removeClass(“highlight"); }) .click(function() { //do something }) .fadeIn(„slow‟);
  • 4. Don‟t leave them hanging. :first-child, :last-child, :even, :odd, :parent, :next, :prev, etc. Precede them with a tag name or some selector; else the universal selector is implied. $(':focus') = $('*:focus')
  • 5. Understand what each does. Use appropriately. $('#sometable').each(function(){ $('td', this).bind('hover', function(){ $(this).toggleClass('hover'); }); }); $('#sometable').each(function(){ $('td', this).live('hover', function(){ $(this).toggleClass('hover'); }); }); $('#sometable').delegate('td', 'hover', function(){ $(this).toggleClass('hover'); });
  • 6. Create in memory. Then update the DOM. var $mylist = $('#mylist'); // <ul> for (var i = 0; i < 100; i++) { $mylist.append('<li>' + bestsellers[i] + '</li>'); } var $mylist = $('#mylist'); // <ul> var concatenatedList = “”; for (var i = 0; i < 100; i++) { concatenatedList += ('<li>' + bestsellers[i] + '</li>'); } $mylist.append(concatenatedList);
  • 7. Bind less. $(„#reports td‟).bind(„click‟, function() { //do something }) $(„#reports‟).bind(„click‟, function(e) { var target = e.target; if (target.nodeName === „td') { // do something } })
  • 8. Choose your event carefully. $(document).ready(function() { //Fires as soon as the DOM is ready //Doesn‟t wait for images, style sheets etc. }) $(window).load(function() { //Fires after all the content is loaded //Includes images, style sheets, etc. })
  • 9. Think right-to-left (except for IDs) $('#user-profiles > li > input:disabled'); $('#user-profiles‟).find(„li > input:disabled');
  • 10. Sizzle engine is highly optimized but… var $someElement = $(„#elementId‟); Vs. var someElement = document.getElementById(„elementId‟); $(„#elementId‟).css(„display‟, „block‟); Vs. document.getElementById(„elementId‟).style.display = „block‟; Do you really need a whole library to accomplish your tasks?
  • 11. Will this improve page performance by x times? Probably, not. (especially if you don‟t have a complex multi-nested DOM) For example, how to better structure your code. • Module Pattern • Revealing Module Pattern • Constructional Pattern • Creational Pattern • Factory Pattern • etc.
  • 12.
  • 13.
  • 14. Essential JavaScript Design Patterns: (Free!) http://addyosmani.com/blog/essentialjsdesignpatternsupdate1 jQuery: Novice to Ninja http://www.amazon.com/jQuery-Novice-Ninja-Earle-Castledine/dp/0980576857 jQuery API http://api.jquery.com JavaScript Performance Testing http://jsperf.com/browse
  • 15. 10 Time-Savers You (Maybe) Don't Know Girish Gangadharan @appoosa girish@giri.sh http://giri.sh