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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:43:19+00:00 2026-06-11T14:43:19+00:00

Possible Duplicate: Javascript event handler on body but not on input I wrote a

  • 0

Possible Duplicate:
Javascript event handler on body but not on input

I wrote a short script that listens the keydown event, but i’d like to ignore it if i’m writing in a text field.

I have no idea about how to do it without strange tricks, like checking if there is a focus on one of the inputs.

Here is my code right now.

document.addEventListener('keydown', function(event) {
    if(event.keyCode == 71) {
        showSelected();
    }
    else if(event.keyCode == 13) {
        closeModal();
    }
});
  • 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-11T14:43:20+00:00Added an answer on June 11, 2026 at 2:43 pm

    This is a little tricky if you’re doing things with contenteditable (like letting users write text inside of any divs/spans/boxes they want to on the page).

    If so, this will take a little thinking and reworking (it’s not that hard – just more involved).

    However, you can check the event.target (element the event’s happening on) for its tagName property, against a list of types you want to exclude.

    function keyEvent (evt) {
        var key = evt.keyCode,
            el = evt.target,
            type = el.tagName.toLowerCase();
            // tag names are upper-case... almost always...
            // so convert one way or the other, to be sure  
        if (type === "input" || type === "textarea") { return; }
        /* do whatever you were going to do */
    }
    

    Should also likely be noted that this solution (and your code thus-far) aren’t ghetto-IE compatible.
    For that, you’d need to work with attachEvent and the window.event and window.event.srcElement properties, because they don’t support addEventListener and the e/event function-parameter.

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

Sidebar

Related Questions

Possible Duplicate JavaScript: Changing src-attribute of a embed-tag but this is not working for
Possible Duplicate: “On file dialog cancel” event in JavaScript Is there a listener for
Possible Duplicate: javascript WYSIWYG HTML editors? Im not quite sure how to put this
Possible Duplicate: Event handlers inside a Javascript loop - need a closure? I have
Possible Duplicate: In JavaScript can I make a “click” event fire programmatically for a
Possible Duplicate: DOM Mutation event in JQuery or vanilla Javascript I am using backbone.js
Possible Duplicate: $(document).ready equivalent without jQuery I have a framework-less javascript that executes on
Possible Duplicate: Javascript window resize event I want to get an event which is
Possible Duplicate: Is there a way to catch the back button event in javascript?
Possible Duplicate: Disabling LinkButton doesn't disable the click event in javascript I have a

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.