Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7764063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:49:04+00:00 2026-06-01T14:49:04+00:00

I have a function in jquery: $(‘#map’).click(function(e) { var posX = $(this).offset().left, posY =

  • 0

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? 😮

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:49:05+00:00Added an answer on June 1, 2026 at 2:49 pm

    You’d define a function outside of the event handlers, then call it from each handler separately.

    function myFunc(e) {
        var posX = $(this).offset().left, posY = $(this).offset().top;
        if (posY < 100) {
    
        }
    
        // if e.which equals 38, the up arrow was pressed
        if(e.which == 38) {
            // do nice stuff here
        }
    
        // the rest of your function here...
    }
    
    $("#map").click(myFunc).keypress(myFunc);
    

    Edit: Threw in jQuery function chaining, too.

    Aha, okay. I think I found your error. I’ve reformatted your code a bit and neatened it up some. Try this:

    function move(e) {
        var posX = $(this).offset().left,
        var posY = $(this).offset().top;
    
        var go = "";
    
        if (posX > 75 && posX < 150 && posY < 75) {
            go = "N";
        }
    
        if (e.which == 38) {
            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));
        });
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got jquery post function jQuery('.more-button').live('click', function(eve){ var page = jQuery(this).attr('id').replace('more-button-',''); loaded_messages +=
I have the following function: jQuery(el).click(function() { var index = jQuery(this).index(), select = jQuery('select.SelectClass
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
i have one function in jquery like this $(#Button_save).click(function() { Save Command; }); this
I have jquery function which looks like this function MonitorLoadStatus(loadId) { var url =
I have this function in Jquery which basically says when you click on the
I have jquery function: function handleSplittingPrices() { var customerId = $(this).val(); loadSplittingPrices(customerId); } I
I have a function that starts like this: jQuery(function($) { $('#map').bind('mousewheel', function(e, delta) {
I have jquery function that is triggered by a 'click' handler: $('#showDatesCheckbox').click(function(){ var table
I have this function $(a#<?php echo $custom_jq_settings['toggle']; ?>).click(function() { jQuery(#<?php echo $custom_jq_settings['div']; ?>).slideToggle(400); jQuery(#featurepagination).toggle();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.