How can we find, the HTML element which fired a event is JavaScript?

arpit_gadle

New member
GO through this code snippet.
<IMG id="img1" src="image1" onmouseover="show(event)">
<IMG id="img2" src="image2" onmouseover="show(event)">

The Javascript
<SCRIPT> show(evt)
{
if(img1)
alert("Evnet fired by Image 1");
if(img2)
alert("Event fired by Image 2");
}
</SCRIPT>
How can we check, which image triggered the event?
Where i can find list of standard functions(not user-defined)?
 
If you don't need to use a function you could use this.
[fakecodetags]
<IMG id="img1" src="image1" onmouseover="alert('image 1')">
<IMG id="img2" src="image2" onmouseover="alert('image 2')">
[/fakecodetags]

Or pass which image was moused over to your function
[fakecodetags]
<IMG id="img1" src="image1" onmouseover="show(this.id)">
<IMG id="img2" src="image2" onmouseover="show(this.id)">

<script>
function show(img){
if (img == "img1"){
alert("Doing stuff"); //Do stuff
}
else if (img == "img2"){
alert("Doing different stuff"); //Do different stuff
}
}
</script>
[/fakecodetags]

Ewww go here for properly formatted code http://pastebin.com/m5c03b8e1
 
Back
Top