• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setAttribute for img event handler

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am dynamically creating an image in an HTML document using "nextImage = document.createElement( "img" )", and I would like to be able to add event handlers that apply to this image (onclick, onmouseover, onmouseout). Whenever I add the code: "nextImage.setAttribute( "onmouseover", "swapImage()" )", nothing happens when I mouse over the image. Is is possible to add an event handler to a dynamically created element using setAttribute or any other DOM method?
As a note, I tried using an anchor as the image's parent, and that allowed me to use setAttribute( "href", "javascript:...") as a substitute for onclick, but I don't want the image to be the child of an anchor, and I still have the problem of rotating images for onmouseover and onmouseout events. Is there an expert out there who is more familiar with this than I am and can help out?
reply
    Bookmark Topic Watch Topic
  • New Topic