I have a function in jquery:
$('#map').click(function(e) {
var posX = $(this).offset().left, posY = $(this).offset().top;
if (posY < 100) {
// do this
When the user clicks within that element it will run. But I also want it to run if he presses a cursor key.
Is it possible to do something like:
$('#map').click OR key.press(function(e) {
Basically, can you set more than one event to run that function? Just learning jquery so go easy on me.
UPDATE
function move(e) {
var posX = $(this).offset().left, posY = $(this).offset().top;
if (posX > 75 && posX < 150 && posY < 75) { var go = "N"; }
if (e.which == 38) { var go = "N"; }
$.post("inc_map.php", { move: go }, function(data){
var substr = data.split('@');
if (substr[0] != "block") {
var x1 = substr[0]; var y1 = substr[1];
x = parseInt(x1) * 32; y = parseInt(y1) * 32;
$("#mapview").css({ backgroundPosition: -x + "px " + -y + "px" });
$("#map").html(substr[2]);
$("#info").html(substr[3]);
};
$("#pos").html((x/32) + ', ' + (y/32));
});
};
$("#map").click(move).keypress(move);
Why doesnt this work? :o