Input Search size Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Search

Description

The size property sets or gets the size attribute of a search field, which sets the width of a search field in number of characters.

The default value is 20.

Set the size property with the following Values

Value Description
number Sets the width of the search field, in number of characters.

Return Value

A Number, representing the width of the search field, in number of characters

The following code shows how to change the width of a search field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Search: <input type="search" id="mySearch" size="35">

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   ww w.j  a  va  2 s  . co  m*/
    var x = document.getElementById("mySearch").size;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials