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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:15:51+00:00 2026-06-18T11:15:51+00:00

I have the following jQuery event: $(#scanItem).live(keydown, function (e) { if (e.keyCode == 13)

  • 0

I have the following jQuery event:

$("#scanItem").live("keydown", function (e) {
    if (e.keyCode == 13) {
        e.preventDefault();
        alert('hi');
    }
});

scanItem is a textbox in my page.

The first time I load the page, everything works fine. Pressing enter fires the event exactly 1 time. However, I have a dropdown that will do a jQuery load to re-load the div.

After the div reloads, when I press enter on the textbox, the alert fires 3 times.

I’ve been scratching my brain for hours on this. Any ideas why this is happening?

  • 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-18T11:15:52+00:00Added an answer on June 18, 2026 at 11:15 am

    If the script is reloaded, then you’re adding event handlers each time.

    An easy solution, if you can’t move the script out of the div, would be to change it to not use live :

    $("#scanItem").on('keydown', function (e) {
    

    To make it work you must ensure the code is after the #scanItem element.

    So this wouldn’t touch future elements with the same id.

    By the way, as live was deprecated and is now removed from new versions, you really should use on instead, directly (like here) or by delegation (which makes it functionally equivalent to live).

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

Sidebar

Related Questions

All, I have the following jQuery code: jQuery(#data_form).submit(function() { event.preventDefault(); alert(it submits); }); When
I have the following jQuery code: $("#someTextInputID").keydown(function(event){ console.log(event.keyCode); console.log("input_box.val(): "+input_box.val()); console.log("input_box.val().length: "+input_box.val().length); }) What
I have the following jQuery Ajax code: $(#new_form).submit(function (event) { event.preventDefault(); $.post(/home/new_ajax, $(this).serialize(), function
I have following jQuery code $('a.editpo, a.resetpass').click(function(event){ event.preventDefault(); var urlToCall = $(this).attr('href'); var hyperlinkid
I have the following in jQuery mobile: <script type=text/javascript> $(#locate_results).live(pageinit, function(event) { $(#venues li
Possible Duplicate: Bind multiple events to jQuery 'live' method I have the following function:
I have the following jquery script: $(function(){ $('#top-menu').on('click', 'a.change-menu', function(e){ e.preventDefault() $(#menu-change-div).load($(this).attr(href)); }); });
I have the following jquery code: $(document).ready(function() { $(body[class*=page-calendar-practices] #content-header h1#title).after(<div id='athletics_practice-schedule'><div id='inner-title'><a href='www.example.com'
I have the following jQuery event that gets fired every time an anchor is
I have the following jquery function for some links $(.clickable).click(function(event){ // load dialog content...

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.