Clicksco / Front-End

Organisation Front End Documentation & Tooling
http://docs.clicksco.com/frontend
2 stars 1 forks source link

When doing any DOM manipulation or lookup, you SHOULD cache the necessary DOM element #71

Closed BenjaminRCooper closed 10 years ago

BenjaminRCooper commented 10 years ago

This is a performance benefit, as you no longer have to reach into the DOM for the necessary element, every time you would like to perform any manipulation.

Bad Example

function myFunc() {
    $('.ele').hide();
    $('.ele').height(30);
    $('.ele').fadeIn();
}

Good Example

function myFunc() {
    var $ele = $('.ele');
    $ele.hide();
    $ele.height(30);
    $ele.fadeIn();
}
jonspark commented 10 years ago

+10

Also +1 for the $ prefix to jQuery object vars

BenjaminRCooper commented 10 years ago

I will create a seperate standard for this one, as it is an approach I use quite often.

Ben

timgale commented 10 years ago

+1

iamrossgrant commented 10 years ago

Best way to do it +1

ampersarnie commented 10 years ago

+1

markgoodyear commented 10 years ago

+1

BenjaminRCooper commented 10 years ago

Implemented