Reputation: 173
How do I get a DOM element and attach an event onClick
?. I tried this code but it does not work:
<div>
<h1 id="some_id">
click here
</h1>
</div>
JavaScript:
Ext.onReady(function() {
if(Ext.getDom('some_id'))
{
var elDom = Ext.getDom('some_id');
elDom.on('click', function(){
Ext.Msg.alert('Status', 'Already get the element from the dom');
});
}
});
Fiddle: https://fiddle.sencha.com/#fiddle/2fl
Upvotes: 1
Views: 129
Reputation: 4435
Another way to do this is to get the Ext.dom.Element
instead of the actual DOM node. This will allow you to use .on()
. This is done by using Ext.get()
instead of Ext.getDom()
.
var elDom = Ext.get('some_id');
if(elDom) {
elDom.on('click', function() {
Ext.Msg.alert('Status', 'Already get the element from the dom');
});
}
Upvotes: 2