One other way is by using the selector:
$$('textarea', 'select')
Arnar
ps sorry Jeff for the double post - forgot "reply-all" :-|
On 1/31/07, Jeff Shell <[EMAIL PROTECTED]> wrote:
>
> On Jan 30, 11:25 am, "Karsten Patzwaldt <[EMAIL PROTECTED]>"
> <[EMAIL PROTECTED]> wrote:
> > Hi.
> >
> > I'm currently trying the following. First, I construct my output HTML
> > via DOM constructors, i.e. DIV(null, A(...), ...). Then, I'd like to
> > traverse the constructed DOM tree in order to append "onchange"
> > attributes to all TEXTAREA and SELECT tags. According to the
> > documentation, DOM is iterable, and imap iterates over iterables, so I
> > tried
>
> If you're specifically adding an onchange handler to textarea and
> select tags, you can use `root.getElementsByTagName('textarea')`, with
> root being the root node that you constructed. `getElementsByTagName`
> is a regular DOM method that is built in.
>
> Alternatively you could use
> `MochiKit.DOM.getElementsByTagAndClassName('textarea', null, root)`.
> Or MochiKit.Selector (if using the SVN Trunk / '1.4' codebase) for
> more complex expressions regarding the child elements you want to
> iterate over.
>
> For example::
>
> var md = MochiKit.DOM, Iter = MochiKit.Iter,
> Signal=MochiKit.Signal;
> var root = buildmytree(...);
> var myhandler = function(e) { ... (onclick handler) }
>
> Iter.forEach(['textarea', 'select'], function(tagname) {
> Iter.forEach(root.getElementsByTagName(tagname),
> function(element) {
> Signal.connect(element, 'onclick', myhandler);
> });
> });
>
> You could probably use other Iter / Base tools to compile these in
> other ways::
>
> list(imap(function(node) { alert(node); return node; },
> chain(imap(root.getElementsByTagName, ['textarea', 'select']))
> ))
>
> I have no idea if that code really works, but it could be a reference
> point for how to get all of the desired elements into a single
> iterable.
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---