954,176 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

event works in IE but not in firefox

Can you help me with the equivalent code of this in firefox?
Thanks in advance.

<html>
	<head>
		<title>Event Handling</title>
		<script type="text/javascript">
		<!--
			//MOUSE COORDINATES
			function updateMouseCoordinates(){
				coordinates.innerText = event.srcElement.tagName + "(" + event.offsetX + "," + event.offsetY + ")";//works on IE not in firefox
			}
		//-->
		</script>
	</head>
	<body onmousemove="updateMouseCoordinates()">
		<span id="coordinates">(0,0)</span>
		
	</body>
</html>
aladar04
Light Poster
38 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

Try mousemove instead of onmousemove.

pritaeas
Posting Expert
Moderator
5,446 posts since Jul 2006
Reputation Points: 653
Solved Threads: 874
 

I don't know why this works in IE, but I know why it doesn't in Firefox. coordinates.innerHTML won't work because coordinates is not a valid object (in Firefox). Instead, use: document.getElementById('coordinates').innerHTML = [...].

iPeterS
Newbie Poster
3 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

Required modifications:
- The innerText property is not supported by Firefox (the textContent property provides similar functionality in Firefox). In that case, the innerHTML property can also be used.
- The event.srcElement property is not supported by Firefox, use the target and srcElement properties together.
- The event.offsetX property is not supported by Firefox, use the cross-browser clientX property instead.
- The window.event property is not supported in Firefox. In Firefox, when an event occurs, an instance of the event object is initialized and passed to the event handlers as the first parameter.

<head>
	<title>Event Handling</title>
	<script type="text/javascript">
	function updateMouseCoordinates (event) {
		var target = event.target ? event.target : event.srcElement;

		var coordinates = document.getElementById ("coordinates");
		coordinates.innerHTML = target.tagName + "(" + event.clientX + "," + event.clientY + ")";
	}
</script>
</head> 
<body onmousemove="updateMouseCoordinates(event)">
	<span id="coordinates">(0,0)</span>
</body>


I think, the following links will be useful to you: event object (event handling) ,
textContent property ,
innerText property ,
innerHTML property ,
target property ,
srcElement property ,
clientX property ,
clientY property .

gumape
Newbie Poster
16 posts since Aug 2010
Reputation Points: 13
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: