Variables


#1

Can someone tell me what is the difference between these two codes? Aside from the fact one has a variable one does not? Why is one in this case better than the other?

=======================================================

$(document).ready(function() {
var $target = $('ol li:nth-child(4)');
$target.fadeOut('fast');
});


$(document).ready(function() {
$('ol li:nth-child(4)').fadeOut('fast');
});

=======================================================
(FYI: I don't know if I wrote the second code correctly I'm just assuming it would make the li tag fade out).

I'm just trying to understand the purpose of using variables? It says to use at a later time but in this example it seems to be use at the same space and time as the second code which is right away? I don't see an indication of it being use later? or being saved for a later time? I never understood that in JavaScript??


#2

var $target = $('ol li:nth-child(4)').fadeOut('fast');
I have done this variable part using this. and it successfully worked..


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.