SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to addEventListener?

    OK, lets make this easy . I wont go into details of my function, I would like to first see it work . So here's the thing:

    I've read a small tutorial about addEventListener but it doesn't work for me. So what I want is this (well, that's not exactly what I want but I just want to know the concept first):

    I have an image. I want when you click on it two alerts appear. Like this:
    <img onclick="alert('a'); alert('b');">

    But I don't want to do it thusly. I want to make it dynamically. So:
    <img onclick="alert('a');">
    and then something like:

    document.getElementsByTagName('img')[0].addEventListener
    but don't know the rest.

    How to solve this?

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just found out. IE doesn't support addEventListener but uses attachEvent instead.

  3. #3
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Rok

    Check out this tutorial:
    http://www.pageresource.com/dhtml/ryan/part4-7.html

    aDog


Bookmarks

Posting Permissions

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