$get Shortcut Method
Provides a shortcut to the getElementById method of the Sys.UI.DomElement class. This member is static and can be invoked without creating an instance of the class.
Syntax
Term |
Definition |
---|---|
id | The ID of the DOM element to find. |
element | The parent element to search. The default is the document element. |
Example
The following example shows how to use the $get method. This code is part of a larger example found in the DomElement class overview.
cs
vb
- // Add handler using the getElementById method
- $addHandler(Sys.UI.DomElement.getElementById("Button1"), "click", toggleCssClassMethod);
- // Add handler using the shortcut to the getElementById method
- $addHandler($get("Button2"), "click", removeCssClassMethod);
--------------------------------------
- // Add handler using the getElementById method
- $addHandler(Sys.UI.DomElement.getElementById("Button1"), "click", toggleCssClassMethod);
- // Add handler using the shortcut to the getElementById method
- $addHandler($get("Button2"), "click", removeCssClassMethod);
$find Shortcut Method
Provides a shortcut to the findComponent method of the Sys.Application class. This member is static and can be invoked without creating an instance of the class.
Syntax
Arguments
- var o = $find(id, parent);
-
id :
-
A string that contains the ID of the component to find.
parent :
-
(Optional) The component or element that contains the component to find.
Return Value
A Component object that contains the component with the specified ID, if found; otherwise, null.
Remarks
For details about the method that this shortcut represents, see findComponent Method.
Example
The following example uses the $find method to check whether a custom component exists and to notify the user if the component is missing.
CS
- function checkComponent() {
- if (!($find('MyComponent', div1))) {
- div1.innerHTML = 'MyComponent is not available.';
- }
- }