| Page 1 of 1 | [ 3 posts ] |
|
Hi,
I was wondering why is that when I use YUI.util.Dom.get I get a reference to a element and not the element itself. Here is the situation where this came up: Code: // this will not work YAHOO.util.Dom.get("some_element").addClass("some_class"); // this wil' work YAHOO.util.Dom.addClass("some_element", "some_class"); Thanks, Nigel |
|
Hello Nigel,
In Javascript there is not object itself, what you get is always a reference to an object, even when you do this: var a = {}; Anyway, that's not the problem here. DOM "get" returns a reference to a DOM element, and "addClass" is not a DOM method, that's why you cannot use the chain approach with it. In the case of the second sentence, DOM "addClass" is a YUI 2 implementation. It uses "get" to collect the reference, then apply a regular expression to see if that class is already applied, if not, it will add it to the class attribute. That said, YUI 3 uses a different approach, Y.one, Y.all and all the other methods that interact with DOM elements use a NODE object instead of a DOM element, which is a YUI 3 implementation to encapsulate a DOM element, and that's why you can do chaining: Code: Y.one('#somelement') .addClass('some_class'); Best Regards, Caridy |
|
Great, thanks for the Javascript lesson!
|
| Page 1 of 1 | [ 3 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group