Let's say I have this block of code:
$('#myBox').css('background', 'grey');
$('#myBox').click( function(e){ console.log( 'Box clicked' ); });
$('#myBox').html(' Just a test text ');
What I know so far is that I'm searching an element with the myBox
ID at every line.
The question: would I benefit from a variable creation when I have multiple references to an HTML element?
Or will the variable still search for the associated element every time I access it? Example:
var $myBox = $('#myBox');
$myBox.css('background', 'grey');
$myBox.click( function(e){ console.log( 'Box clicked' ); });
$myBox.html(' Just a test text ');