Archive October 2011
#1 Crime of jQuery – DOM Abuse
The Crime
Here is an example,
$(function(){
$('#id').change(function(){
//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!
