Archive October 2011

#1 Crime of jQuery – DOM Abuse

The Crime

Here is an example,

    //do stuff

  $('#id').css('border-color', '#ff0000');
  var val = $('#id').val();

See what is happening here?
There are several calls to $(‘#id’).

The reasoning

Why is this so bad?
Well, imagine the DOM as a giant pool of all elements on your page, every time you call $(‘#id’)¬†you are diving into the pool and swimming around until you find the element you need. That adds some serious overhead on every call!

Read more


That's Me, I'm a web developer who's main focus is actually Back-end, Specifically PHP development. But every now and then I come up with something awesome for the front-end and this is where I share it!

More updates on Twitter