question about jquery click event

1 view
Skip to first unread message

amrita

unread,
Feb 21, 2010, 1:36:39 PM2/21/10
to EDUC 176 Programming Lab
Hi Troy, Steve,

I am trying to read in the X,Y co-ordinates of a mouse click on a div,
and I can read it using the following

$('#baseboard').click(function(event){
$('#showxy').html("X: " + event.pageX + " Y: " +
event.pageY);
});


what I would like to do is move the function to a separate function
and call it from here, and I tried defining it as
baseboardWasTapped(event) ... but that did not work. Do you have any
ideas on what I should do ?

Thank you,
Amrita

Steve Marmon

unread,
Feb 21, 2010, 2:13:06 PM2/21/10
to EDUC 176 Programming Lab
Hi Amrita,

It sounds like you are on the right track. I just tried this out for
myself, and it worked fine. Here is the code that worked for me:

function createBalloon() {
...
// Add the event handler
newBalloon.click(balloonClicked);
}

function balloonClicked(event) {
alert(event.pageX);
}

- Steve

Reply all
Reply to author
Forward
0 new messages