0

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?

rollo
  • 305
  • 3
  • 14
  • 1
    See http://stackoverflow.com/questions/11849692/jquery-object-to-cache-or-not-to-cache , http://stackoverflow.com/questions/9296231/to-cache-or-not-to-cache-this-in-jquery – guest271314 Aug 26 '14 at 06:30
  • ty.. seems that i wasn't searching the right term 'cache'.. – rollo Aug 26 '14 at 06:41

0 Answers0