What are the way to access DOM elements in Ext JS?
Usage
// by id
var el = Ext.get("my-div");
// by DOM element reference
var el = Ext.get(myDivElement);
Selecting Descendant Elements
Ext.dom.Element instances can be used to select descendant nodes using CSS selectors. There are 3 methods that can be used for this purpose, each with a slightly different twist:
These methods can accept any valid CSS selector since they all use querySelectorAll under the hood. The primary difference between these three methods is their return type:
To get an array of HTMLElement instances matching the selector '.foo' use the query method:
element.query('.foo');
This can easily be transformed into an array of Ext.dom.Element instances by setting the
asDomparameter to false:element.query('.foo', false);
If the desired result is only the first matching HTMLElement use the selectNode method:
element.selectNode('.foo');
Once again, the dom node can be wrapped in an Ext.dom.Element by setting the
asDom parameter to false:element.selectNode('.foo', false);
Comments
Post a Comment