It holds a reference to the jQuery object that was returned. Any changes to the object change the underlying DOM element and all other references to the same element.
$('div .complicated #selector ul:last')
Your variable objectToReference
will be a jQuery object that you can perform jQuery operations on. Also, even though you don't have to, you can also use objectToReference
to create a new jQuery object, which shouldn't impose any performance limitations since it should just return a reference to itself and not re-search for that element.
var objectToReference = $('div .complicated #selector ul:last');
var copyOfObject = $(objectToReference);
You may have run into problems by trying to reference DOM properties of the objectToReference
. If you want to get at the underlying DOM element of your objectToReference
returned by the jQuery selector, you can do this:
var objectToReference = $('div .complicated #selector ul:last');
var domOfObject = objectToReference.get(0);
Or optionally, you could do this, which does the same in 1 line:
var domObjectToReference= $('div .complicated #selector ul:last').get(0);
Again, you can use the domObjectToReference
in the jQuery constructor to create another reference to that object:
var objectToReference2 = $(domObjectToReference);
All of these examples store references to the DOM element. If you modify the value of one of the references, they will all be modified/updated.