-2
I need a help, I set up a function to lock the space be keyboard on the first element of input
would like to have the function run in all fields, but it only blocks in the first field the other fields the function does not work.
var input = document.querySelector('input');
input.addEventListener("keypress", function(e) {
if (this.selectionStart === 0) {
if (e.which === 32 ) {
e.preventDefault();
}
}
});
<input type="text" id="campo1">
<input type="text" id="campo2">
<input type="text" id="campo3">
querySelector
only returns an element; if you need all usequerySelectorAll
.– Woss
when I use querySelectorAll function does not work in any field
– Fragosojp
Yes, please read the documentation for this function to understand how it works: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
– Woss