Jonathan Wood Jonathan Wood - 5 months ago 16
jQuery Question

Meaning of $get('0')?

I just upgraded to jQuery 1.12 from an older version. I'm going through the code, trying to resolve breaking changes.

One such change is occurring in the following code:

$(document).ready(function() {
Sys.Application.add_unload(applciationUnloadHandler);
function applciationUnloadHandler() {
var contactDropDown = $get('0');
createCookie('NewProgram_ContactID_Cookie', contactDropDown.value, null);
}
});


This code fails because
$get('0')
returns
null
.

But I really don't understand what this is supposed to be doing. I don't see
$get()
defined anywhere. I can see from looking at the code behind that the
'0'
argument represents a contact ID, but I can't see what the code is supposed to be doing.

Answer

$get is a shortcut function for Sys.UI.DomElement.getElementById

The $get method provides a shortcut to the getElementById method of the Sys.UI.DomElement class.

Reference