Categories
- Andy and Javi: Actionscript and AIR Quick Tips
- Arc90
- Architecture
- Avi and Patrick: Java Quick Tips
- Avi: REST Quick Tips
- Ben and Matt: PHP Quick Tips
- Business
- Chris and Corey: JQuery Quick Tips
- Chris and Matt: Unix Quick Tips
- Design
- Development
- Foresight
- Javi: CF Quick Tips
- Jobs
- Joel: .Net Quick Tips
- Lab
- Music
- Patrick and Joel: XML Quick Tips
- Reviews
- Tech
- The Internets
- Thoughts
- Trends
- Web
- What We Are Reading
Archives
Category Archives:
Chris and Corey: JQuery Quick Tips
Posted on March 17, 2008 by Corey Maass
Avoiding Repetitious Code in JQuery
A good tip in any coding language is to not repeat code. If you find yourself using a bit of code more than once, make it a separate function. In JQuery, you have the advantage of expanding the JQuery object to include your code. If you want to have the code process JQuery-selected items, use jQuery.fn.nameOfFunction. Otherwise, use jQuery.nameOfFunction. Finally, if you find yourself extending JQuery a lot, use jQuery.fn.extend and put all your code in one place.
1) JQuery extended function when you want to access a JQuery array of elements: Example use: 2) JQuery extended function: Example use:
Permalink | Comments (0) | Technorati Tags : jquery
