I would bind an event handler to keydown
and prevent the default action of that event if we’re dealing with the backspace key outside of a textarea
or input
:
$(document).on("keydown", function (e) {
if (e.which === 8 && !$(e.target).is("input, textarea")) {
e.preventDefault();
}
});
Related Contents:
- Stop form refreshing page on submit
- How does this JavaScript/jQuery syntax work: (function( window, undefined ) { })(window)?
- Changing the image source using jQuery
- Make cross-domain ajax JSONP request with jQuery
- How to get the text node of an element?
- No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘…’ is therefore not allowed access
- What is the difference between $(window).load and $(document).ready?
- How can jQuery deferred be used?
- How to change value of object which is inside an array using JavaScript or jQuery?
- How do I delay a function call for 5 seconds? [duplicate]
- Is there an easy way to convert jquery code to javascript? [closed]
- Set custom HTML5 required field validation message
- Programmatically trigger “select file” dialog box
- How to trigger click on page load?
- Use images like checkboxes
- How to send a message to a particular client with socket.io
- Get query string parameters url values with jQuery / Javascript (querystring)
- jquery’s live() is deprecated. What do I use now?
- Compare 2 arrays which returns difference
- Getting Bootstrap’s modal content from another page
- jQuery drop down menu closing by clicking outside
- $.each() vs for() loop – and performance
- Get URL from background-image Property
- How to fix div on scroll [closed]
- Variables set during $.getJSON function only accessible within function
- How to get html elements from an object tag?
- document.getElementsByClassName().innerHTML always returns “undefined”
- JavaScript keypress event not raised on Android browser
- Why jQuery cannot trigger native click on an anchor tag?
- Can javascript access iframe elements from the parent page?
- How to check if input date is equal to today’s date?
- Eliminate 300ms delay on click events in mobile Safari
- Is there a way to zoom into a D3 force layout graph?
- JavaScript Detecting Valid Dates
- Nested JSON objects – do I have to use arrays for everything?
- jQuery animated number counter from zero to value
- Google MAP API v3: Center & Zoom on displayed markers
- Fullscreen API: Which events are fired?
- Fill available spaces between labels with dots or hyphens
- Better way to prevent browser caching of JavaScript files
- Saving and loading an image from localStorage
- how to compare two elements in jquery [duplicate]
- How can I get the text of an element without children in JavaScript?
- Get cursor or text position in pixels for input element
- Can I save input from form to .txt in HTML, using JAVASCRIPT/jQuery, and then use it?
- Disabling middle click scrolling with javascript
- The data-toggle attributes in Twitter Bootstrap
- javascript date + 7 days
- Get value from text area [duplicate]
- Jquery get form field value