5. Using functions to select HTML elements


$(document).ready(function() {
    $fade = $('div');

$(document).ready(function() {

Regarding these two bits of code, if I had to make a div fade, which would be better?



Hi Tyoungg,

There's not always a ‘better’ version of code. But, in this case, I'd go with the second unless you need to do other stuff with the <div> later on in your code. If you're doing more than a few things with something, storing it in a variable is often a good idea :slightly_smiling:


Thanks for the reply!