Skip to content

Instantly share code, notes, and snippets.

@holloway
Created September 29, 2016 22:18
Show Gist options
  • Select an option

  • Save holloway/0e284240f48888b2444c90202024c8b5 to your computer and use it in GitHub Desktop.

Select an option

Save holloway/0e284240f48888b2444c90202024c8b5 to your computer and use it in GitHub Desktop.

Revisions

  1. holloway created this gist Sep 29, 2016.
    17 changes: 17 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@

    ## Cache your selectors

    Don't do this:
    ```JavaScript
    $("body").on("click", function() {
    $("body").addClass("clicked");
    });
    ```
    Do this:
    ```JavaScript
    var $body = $("body");

    $body.on("click", function() {
    $body.addClass("clicked");
    });
    ```