Results 1 to 3 of 3

Thread: event object

Hybrid View

  1. #1
    Join Date
    Feb 2011

    event object


    I have recently read an old (not updated) book about javascript.

    In the book that talk about the ability of the father object to capture the event of the sun and to detect it.

    They used in the object event and event.srcElement.type and event.srcElement.name, I tried and it worked for me.

    When I searched in google for this, I could not find a direct information about this type of object but more about surround topics like events in Javascript in general.

    Can someone know about good source in the internet that explain about the event object and srcElement etc etc

  2. #2
    Join Date
    Oct 2010
    Versailles, France
    See, at first, this pages from Peter-Paul Koch about events...

  3. #3
    Join Date
    Dec 2005
    Here's an example:

    HTML Code:
    <div id="parent">
      <div id="child">
         <a href="#" id="anchor1">Click Me</a>
      <div id="sibling">
         <a href="#" id="anchor2">Click Me</a>
    Look at the hierarchy of this snippet, it looks kind of like this

    	   /				     \
    	child					sibling
    	|					|
    	anchor1					anchor2
    Whenever an event (like a click, focus, hover) happens in JavaScript, the event object that occurs tries to get to the top of the hierarchy. If I was to mouseover anchor1, then, child and parent would also receive the mouseover event object because it would 'bubble up' the tree.

    If I was to mouseover anchor2, sibling and parent (and anything above them) would also receive the event object.

    You can stop an event object from bubbling up the tree using certain methods like returning false in a callback or using the .stopPropagation() method (https://developer.mozilla.org/en/DOM...topPropagation) which, quite literally, stops the event from propagating up the tree.

    Hopefully that sheds some light on it for you. Great question by the way, it's great to know how DOM events actually work - makes trouble shooting a lot easier than if you just started using them without understanding them.
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center