Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJs - Get element by div class?

Tags:

extjs

extjs4.1

How do I get the ExtJs component object of a Div by class name?

Say my div is:

<div class="abc"></div>

How do I get the ExtJs object of this Div to perform e.g. getWidth()

Note: There is no id given.

What I tried:

Ext.select(".abc")
Ext.query(".abc")

Edit:

Error: Object has no method 'getWidth'

<div id="main">
<div class="abc"></div>
</div>
  var d = Ext.get( "main" );
  d.query('.abc').getWidth();
like image 818
Shlomo Avatar asked Nov 14 '12 12:11

Shlomo


Video Answer


1 Answers

Use

var dom = Ext.dom.Query.select('.abc');
var el = Ext.get(dom[0]); 

This will return an Ext.Element. You can then use ext methods on el like so

el.on('click', function(){}, scope);

or

el.getWidth()
like image 105
Varun Achar Avatar answered Nov 05 '22 19:11

Varun Achar