jQuery Best Practices

Corey Light

November 2013 / Show-Me Tech

Why jQuery?

  • Easy + Readable
  • Chainable
  • Flexible
  • Collaborative + Popular
    176+ contributors

Let's Remember...

  • jQuery is a function
  • $ is not magic (although it is money)
  • $ is not appropriate for all uses

This talk is not about general JS best practices, so let's assume we are using an object literal notation or something close to it, with (lots of!) named functions.

Let's get the basics down

Selectors take time - chain them!

Don't guess it, test it!

Keep it D.R.Y. and cache those selectors too!

Benefits:
  • More flexible
  • $ doesn't have to look up your DOM element every time

String manipulation > DOM manipulation

Benefits:
  • Faster, noticeably so when dealing with a lot of elements
  • More flexible to remove and modify strings independently

General Best Practice

Tips + Tricks

Questions?

Thanks!