Kod
<html>
<head>
<script type="text/javascript">
function whichElement(event)
{
var tname
tname=event.srcElement.tagName
alert("You clicked on a " + tname + " element.")
}
</script>
</head>
<body onmousedown="whichElement(event)">
<p>Click somewhere in the document. An alert box will alert the tag name of the element you clicked on.</p>
<h3>This is a header</h3>
<p>This is a paragraph</p>
<img border="0" src="ball16.gif" width="29" height="28" alt="Ball">
</body>
</html>
<head>
<script type="text/javascript">
function whichElement(event)
{
var tname
tname=event.srcElement.tagName
alert("You clicked on a " + tname + " element.")
}
</script>
</head>
<body onmousedown="whichElement(event)">
<p>Click somewhere in the document. An alert box will alert the tag name of the element you clicked on.</p>
<h3>This is a header</h3>
<p>This is a paragraph</p>
<img border="0" src="ball16.gif" width="29" height="28" alt="Ball">
</body>
</html>
niestety nie działa on pod Firefox'em! W konsoli JS wyskakuje komunikat:
"Błąd: event.srcElement has no properties (...)"
Pod Operą ten kod działa bardzo dobrze. Czy wie ktoś jak trzeba to przerobić, aby działało też pod Firefox'em?!