HTML DOM Input Number Object

Number Object

The Number object is a new object in HTML5.

The Number object represents the HTML <input type="number"> element.

Note:Internet Explorer 9 and earlier versions do not support the <input type="number"> element.

Access Number Object

You can access the <number> element by using getElementById():

var x = document.getElementById("myNumber");

Try it yourself

Tip:You can also traverse the form's elements collection to access the Number object.

Create Number Object

You can create a <number> element by using the document.createElement() method:

var x = document.createElement("INPUT");
x.setAttribute("type", "number");

Try it yourself

Number Object Property

Properties Description
autocomplete Set or return the autocomplete attribute value of the number field.
autofocus Set or return whether the number field should automatically focus after the page is loaded.
defaultValue Set or return the default value of the number field.
disabled Set or return whether the number field is disabled.
form Return a reference to the form that contains the number field.
list Return a reference to the datalist that contains the number field.
max Set or return the value of the number field's max attribute.
min Set or return the value of the number field's min attribute.
name Set or return the value of the number field's name attribute.
placeholder Set or return the value of the number field's placeholder attribute.
readOnly Set or return whether the number field is read-only.
required Set or return whether the number field must be filled out before submitting the form.
step Set or return the value of the number field's step attribute.
type Return the form element type of the number field.
value Set or return the value of the number field's value attribute.

Input Number object methods

Method Description
select() Select the content of the number text field.
stepDown() Decrement the value of the number field by the specified number.
stepUp() Increment the value of the number field by the specified number.

Standard properties and events

The Number object supports standardsPropertiesAndEvents.

Related Pages

HTML Tutorial:HTML Forms

HTML Reference Manual:HTML <input> tag

HTML Reference Manual:HTML <input> type attribute