Re: [Beginner] Associating event handlers with elements
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: [Beginner] Associating event handlers with elements

From: Danny <dann90038@bluebottle.com>
Date: Sun Aug 07 2005 - 21:31:24 CEST

        There are a couple of ways of binding event listeners:

        OBJECT.EVENTTOLISTEN=HANDLERWITHNOARGUMENTS;
        or DOM
        OBJECT.addEventListener(sEVENT,oHANDLERWITHNOARGUMENTS);
        or for IE's
        OBJECT.attachEvent(sEVENT,oHANDLERWITHNOARGUMENTS);
        where HANDLERWITHNOARGUMENTS is usually a function called

        Now, tables have a cells[] collection you can access and a rows[]
collection, you can iterate through either or both, and each node has its
own childNodes[] collection you can also iterate through doing the event
binding.

        a 3rd technique is using a listener on the parent element and checked the
bubbled object

        document.onclick=something;

        function something(ev) {
                        // in IE the evented node will be event.srcElement
                        // in mozilla/opera(opera uses either target or srcElement) the node is
ev.target
          alert(ev.target.nodeName) // will show the element tagName, so, if you
click on a cell, it'll be 'TD'

                }

        Using the 3rd tecnique, you set the event listening ONCE and check the
child that was evented and process accordingly, without having to bind a
handler/listener to each on a loop.

                                                                Danny

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Received on Tue Oct 18 03:06:22 2005