Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: How to set an event response using DOM in NN6 & IE5.5?


Message #1 by Paul Masri <paulmasri@b...> on Mon, 30 Jul 2001 18:10:55 +0100
I've been using the setAttribute(attr,value) to set the properties of DIV and
IMG nodes, as per Paul Wilton's book.  Now I also want to be able to set an
event.

For example:
If I have the HTML
  <DIV id="MyDiv"><IMG src="MyImage.gif" onmouseover="MyFunction()"></DIV>

and in a piece of script I put
  var x=document.getElementById("MyDiv").firstChild;
  alert("src="+x.getAttribute("src")+", onmouseover="
    +x.getAttribute("onmouseover"));

in IE5.5, an alert is generated saying:
"src=[complete source path]/MyImage.gif, onmouseover=function anonymous() {
MyFunction() }"

If I add the line x.setAttribute("src","NewImage.gif")
then the src attribute gets changed and the image changes in the browser.

However, if I add x.setAttribute("onmouseover","function anonymouse() { NewFn()
}
or even x.setAttribute("onmouseover","NewFn()")

then the attribute appears to have changed (ie. getAttribute() shows a change),
but it has no actual effect on the page.

How can I add, change or remove an event response in NN6 and IE5.5?

Thanks,
Paul.

  Return to Index