Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Simulate the 'Backspace' button being pressed in JS/JQuery

Featured Replies

Hello,

 

I currently have an input field which I am using as a search field. I have incorporated JQuery Ajax so that when you start typing in the input field it uses what has been typed and creates an <ul> of all the names which contain the input letters (In the same order they have been typed).

 

The <ul>, which appears, hovers over my other divs and only appears when there is text in the input field. So, for example, if you type something in the input field, and then delete them all, the <ul> would disappear.

 

When selecting one of the names from the list, I use this to trigger another event which loads relevant fields in the page, with the corresponding data to the person who's name you have clicked. This then get's triggered:

 

$(document).ready(function() {
            $(".search").change(function() {
                $('#search').val('');
            });
        });

This picks up on the event of clicking on a name from the drop-down list and it successfully clears the input field (After running my other queries).

 

HOWEVER the floating <ul> does not disappear. You have to then click in the empty input field and press the backspace key for it to disappear. Hence why I am wanting to find out how to simulate a backspace press using javascript / jquery.

 

Any help with this matter will be greatly appreciated as I have been stumped with this for far too long now.

 

Many thanks,

 

- MjA -

Edited by SkullBob

Would adding focus to the field work?

 

$(document).ready(function() {
     $(".search").change(function() {
          $('#search').val('').focus();
     });
});

Edited by Mikec1uk

  • Author

@ Mikec1uk - I added the '.focus()' and this has still not fixed the issue.

 

 

- MjA -

Edited by SkullBob

  • Author

@D4Y0 - I will send you a message with the details for where the site is hosted, and the login details, so you can have a look. I don't want to share sensitive information with too many people.

 

- MjA -

  • Author

Thank you so much. It can be so annoying spending so long on something to find out that you only needed to include the following to fix it.

 

.trigger("keyup");

I was stuck with this for hours.

 

Many thanks.

 

- MjA -

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.