I wonder why default maxLength/minLength property for HTMLInputElement is set to -1 by default.
There is also confusing behavior like below:
<input type="text" />
const inputElement = document.querySelector('input');
console.log(inputElement.maxLength) // -1
maxLength
programaticallyinputElement.maxLength = 2;
console.log(inputElement.maxLength) // 2
and html will reflect as
<input type="text" maxlength="2" />
maxlength="2"
manually from devtools.<input type="text" />
I get
console.log(inputElement.maxLength) // undefined
can someone tell me why is that? There is no such a thing in documentation, but i can see that every browser is pretty consistent in this.
[Edit] 3. is wrong in this example, it is return -1 https://stackoverflow.com/a/75541575/10465908
So answer to my original question is https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#limited-to-only-non-negative-numbers as maxLength
is type long
.
But I discovered some interesting things during the investigation: