The jquery "on click" function gets triggered on key press "enter"

Pressing the Enter Key whilst focused on a button is treated in the same way as a click event by the browser.

As Rory has mentioned, this is a feature by design of all Browsers, if you wish to negate this feature end users may be unhappy with the end result as it will not have all the Standard functionality.

To negate this you could have a check for onkeydown/onkeyup/onkeypress to check whether a keyboard action occurs prior to the click event firing and stop the click events code firing if a key was pressed.

i.e.

var isKeyPress = false;

document.onkeydown = function(event) {
   if (event.keyCode == 13) {
      isKeyPress = true;
   }
}

jQuery(".multipleDataRow").on("click", "[id^='multiremove_']", function() { 
   if (!isKeyPress) {
      //code here to delete
   }
   isKeyPress = false;
});

This should stop the click events code running if the isKeyPress value is true


This is by design of all browsers. It's an accessibility feature, and should therefore not be tampered with.

If it is causing unintended behaviour in your site, change your HTML markup to work around it.

Tags:

Jquery