I am working with jquery to manipulate DOM elements. I was wondering what is the best approach to load elements from DOM. i.e. will it be more appropriate to load all elements from DOM at once and then use the saved elements to do more operations on it?
var $txtName,$txtAddress;
function LoadDOM()
{
$txtName=$('#txtName');
$txtAddress=$('#txtAddress');
}
function doSomething()
{
$txtName.val('Name');
$txtAddress.val('Address');
}
Earlier I used to do following
function doSomething()
{
$('#txtName').val('Name');
$('#txtAddress').val('Address');
}
Am I doing this right?