Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

clientX events not working in FF 1

Status
Not open for further replies.

maharg

Technical User
Mar 21, 2002
184
Hi folks,

I am having no joy making this simple mouse event script work in FF.
If anyone could give me a clue what I need to do do make it compat with most modern browsers I'd be very grateful.

Thanks,

Graham

Code:
<!doctype html>
<html>
<head>
<script src="[URL unfurl="true"]http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>[/URL]
</head>
<body>

<div style="width:1000px; height:500px; background-color:#dddddd"></div>


<script>
$("div")

.mousedown(function() {
var coorddnx=event.clientX;
var coorddny=event.clientY;
$( this ).append( "Down: x="+coorddnx+", y="+coorddny+"<br>" );
})

.mouseup(function() {
var coordupx=event.clientX;
var coordupy=event.clientY;
$( this ).append( "Up:  x="+coordupx+", y="+coordupy+"<br><br>" );
});
</script>


</body>
</html>
 
Hi

What is that "event" ? I have no idea. Neither my FireFox has :
console said:
[COLOR=white red] X [/color] [red]ReferenceError: event is not defined[/red]
[green]var coordupx=event.clientX;[/green]​

Hint : the current event is passed as parameter to the callback function.


Feherke.
feherke.ga
 
Thanks You! all working great now!

Code:
<!doctype html>
<html>
<head>
<script src="[URL unfurl="true"]http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>[/URL]
</head>
<body>

<div style="width:1000px; height:500px; background-color:#dddddd"></div>


<script>
$("div")

.mousedown(function(event) {
if (!event) var event = window.event;
var coorddnx=event.clientX;
var coorddny=event.clientY;
$( this ).append( "Down: x="+coorddnx+", y="+coorddny+"<br>" );
})

.mouseup(function(event) {
if (!event) var event = window.event;
var coordupx=event.clientX;
var coordupy=event.clientY;
$( this ).append( "Up:  x="+coordupx+", y="+coordupy+"<br><br>" );
});
</script>


</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top