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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:24:31+00:00 2026-05-14T06:24:31+00:00

I am trying to disable the backspace key in my jQuery app, so that

  • 0

I am trying to disable the backspace key in my jQuery app, so that it does not cause the browser to go back a page. However, I do not want to disable it if an input or textarea element is focused, because I want backspace to work properly there.

So, I want to select anything that is not an input or textarea.

Here is the code. The problem is that it fires for every element, even inputs and textareas.

    $(':not(input, textarea)').keydown(function(e) {
    if (e.keyCode === 8) {
        return false;
    }
});

I do not understand why the :not() function is not working. Is there a better way I can do this?

Note that if I remove the :not() function, it works properly. That is, it only fires for input and textarea elements.

EDIT: Based on the accepted answer, here is code that works. I am sure there is a better way to do this.

    $(document).keydown(function(e) {
    var element = e.target.nodeName.toLowerCase();
    if (element != 'input' && element != 'textarea') {
        if (e.keyCode === 8) {
            return false;
        }
    }
});
  • 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-14T06:24:31+00:00Added an answer on May 14, 2026 at 6:24 am

    Your problem is that the keydown event bubbles from the <input> or <textarea> element to the normal element that contains it, firing the event from that element.

    You need to check e.target.

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

Sidebar

Related Questions

I have a web app. I'm trying to disable/prevent the scrolling that occurs when
I'm trying to disable the backspace button on an order page in all cases
I am trying to disable specific dates using the JQuery Ui. However, I am
I'm trying to disable a bunch of controls with JavaScript (so that they post
I am trying to disable ASP.Net Validator such that its disabled on postback. I
I'm trying to disable registry reflection in WiX. Because I want to write in
So I'm trying to disable scrolling on my page when my lightbox opens, and
I am trying to disable parts of the UI in a .NET app based
I'm trying to disable top menu on jQuery UI Tabs - so the tabs
I am trying to disable validators using jquery. I have already looked Disable ASP.NET

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.