-
20 Aug 2010 1:11 PM #1
Unanswered: How to get element from inside event handler
Unanswered: How to get element from inside event handler
I want to add a class to an element that has been clicked on:
Everything works up to the last line, where t.addClass() gives me the following error:Code:Ext.select ("div#topmenu ul li a").on ("click", ( function (e, t, o) { e.stopEvent(); Ext.get ("middle").load ({ url: this, scripts: true }); Ext.select ("a.active").removeClass ("active"); t.addClass ("active"); // ERROR } ));
I am unable to locate any documentation on "HTMLElement", which I assume is distinct from Ext.Element.Code:Uncaught TypeError: Object #<an HTMLElement> has no method 'addClass'
In any case, how can I get add a class to this element?
-
20 Aug 2010 10:36 PM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 44
- Answers
- 1
It's:
Code:Ext.fly(t).addClass('active');
-
21 Aug 2010 2:39 AM #3
Hrm, still doesn't work (although no errors now). Here's the complete code:
This isn't a huge deal for me as the jQuery code is working fine (I was just hoping to reduce my dependencies a bit), but if it *should* work, then consider this a bug report ;-)Code:Ext.onReady ( function () { Ext.BLANK_IMAGE_URL = "/js/extjs/resources/images/default/s.gif"; Ext.select ("div#topmenu ul li a").on ("click", ( function (e, t, o) { e.stopEvent(); Ext.get ("middle").load ({ url: this, scripts: true }); Ext.select ("a.active").removeClass ("active"); Ext.fly (t).addClass ("active"); } )); });
-
21 Aug 2010 3:12 AM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 44
- Answers
- 1
I would use:
Code:Ext.onReady(function () { Ext.get('topmenu').on('click', function(e){ Ext.get('middle').load({ url: e.getTarget().href, scripts: true }); Ext.select('#topmenu a.active').removeClass('active'); Ext.fly(e.getTarget()).addClass('active'); }, null, {delegate: 'a', stopEvent: true}); });
Similar Threads
-
Viewport inside form element, insted of body element
By ncardeli in forum Ext 2.x: Help & DiscussionReplies: 17Last Post: 19 Mar 2010, 7:11 PM -
[CLOSED][3.0.0] Event handler arguments receive DOM element instead of Ext.Element
By jherfurth in forum Ext 3.x: BugsReplies: 6Last Post: 18 Jul 2009, 12:30 PM -
Simple Event Handler for an HTML element
By databass in forum Ext GWT: DiscussionReplies: 2Last Post: 9 Jun 2009, 1:36 PM -
XTYPE Event Handler embedded inside a panel
By anshubansal2000 in forum Ext 2.x: Help & DiscussionReplies: 4Last Post: 19 Jan 2009, 2:59 PM -
is there EXT event and event handler at the page close
By mxu in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 22 Jan 2008, 2:07 PM


Reply With Quote