Saturday, March 24, 2012

Wrapper for getElementsByTagName?

Does the client reference have a wrapper for document.getElementsByTagName like it does with ById/$get ?

Sorry the current version as well as the future does not not have any shortcut. But the future has a new shortcut which works on the css selector.


Is there some way through the client stack to check if a dom element has had a certain handler already added? Say I want to check if a textbox already has a handler {focus:SomeFunction} before I add the handler?


No, client reference doesn't have a wrapper for document.getElementsByTagName like it does with ById/$get


There's no 'wrapper' for ~ByTagName but you could easily write your own and put it in a utils file that you pull down. e.g.:

function $getTags(tagName){
return document.getElementsByTagName(tagName);
}

you can get a list of event handlers by calling get_events() on your element. To do what you're asking, you could say something like, var focusHandler = el.get_events().getHandler('focus'); if focusHandler is null, then you know you don't have anything handling focus yet.

No comments:

Post a Comment