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 7505315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:52:21+00:00 2026-05-29T21:52:21+00:00

I want to pass a keydown event to another element. Along the way I

  • 0

I want to pass a keydown event to another element. Along the way I found that :

$('input').keydown(function(e) {
    $('textarea').keydown()[0].focus();
});

works and that:

$('input').keydown(function(e) {
    setTimeout(function() { $('textarea').keydown()[0].focus(); }, 0);
});​

doesn’t work. At least in Chrome.

Anyway I want to do this with the second method as I want it to first be able to do a ctrl+c or ctrl+x on an input that has text selected and then jump to the textarea.

Here’s a DEMO to see what I mean.

Why doesn’t the second way work? Also is there any way to accomplish this?

  • 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-05-29T21:52:23+00:00Added an answer on May 29, 2026 at 9:52 pm

    Works as expected. First of all, half of your code is irrelevant. :p

    $('inout').keydown(function(e) {
      $('textarea').keydown()[0].focus();
    });
    

    is equivalent to

    $('inout').keydown(function(e) {
      $('textarea').keydown(); // doesn't do anything sensible
      $('textarea')[0].focus();
    });
    

    and it transfers the focus to the textarea before the keyhandler resolves. The key ends up in the textarea. and the input doesn’t even see it. (assume the code says input and not inout).

    The second example:

    $('input').keydown(function(e) {
      setTimeout(function() { $('textarea').keydown()[0].focus(); }, 0);
    });​
    

    is equivalent to:

    $('input').keydown(function(e) {
      setTimeout(function() {
        $('textarea').keydown(); // doesn't do anything sensible
        $('textarea')[0].focus();
      }, 0);
    });​
    

    so, because of the timeout, first the keydown event completes, the key is accepted as input to the input, and then the delayed function gets invoked and changes focus. Nothing further happens.

    I don’t know how to “repeat” or “rethrow” a keyboard event, in case you want to get the same keypress in both input and textarea (if that’s what you wanted; I am not 100% sure what you wanted).

    EDIT: Okay: if it’s just Ctrl/Shift/another modifier key, return true so the default handler picks it up. If it’s Ctrl-C (i.e. C key with ctrlKey set (metaKey on Mac), do the timeout thing (so the input catches it before the focus); if not, move focus immediately (so the textarea catches it). Not trivial, and I can’t think of a better method at the moment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass parameters when an event is triggered. My function: private function
I'm trying to pass an keydown event from one textbox to another. What I
I want to pass an ImageIcon instance by value as we know that by
I want to pass a string that contains few words to jQuery when click
I want to pass an uninitialized object pointer to some method. Within that method
want to pass boost::bind to a method expecting a plain function pointer (same signature).
I want to pass a variable along with the link on a button click,
I want to pass buttonClick method as a parameter to the function: we have
I want pass a sub data type into function. An example: data Car a
How do i create and pass the event to event handler? Basically i want

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.