View Full Version : jQuery to EXTJs

26 Aug 2009, 6:23 AM
How do I do this in EXTJS?

$('#myNav li a').bind('click', function(){

26 Aug 2009, 6:36 AM
Instead of relying on a composite element to query the DOM, return a collection of elements and loop through them adding listeners (leaving the possibility of more being added later, but being missed), in Ext, you'd add one listener.

And use the delegate option to filter the events to select only those from elements matching a selector string:

Ext.get('myNav').on('click', function(e) {
alert(e.getTarget().value); // "value" of an <a> element????
}, null, { delegate: 'li a' });

26 Aug 2009, 6:38 AM
You could if you really want to have a separate listener for each element, as jQuery would give you, use:

Ext.select('#myNav li a').on('click', function(e) {
alert(e.getTarget().value); /// again, "value"? Of an <a> element?

But that would mean that if any "li a" elements were added dynamically to #myNav, then you would not receive the clicks.... exactly as in jQuery.