Javascript DOM HTML Input Search type Property

Introduction

Return which type of form element the search field is:

var x = document.getElementById("mySearch").type;

Click the button to display which type of form element the search field is.

View in separate window

<!DOCTYPE html>
<html>
<body>

Search: <input type="search" id="mySearch">
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*from  www .j a v a2s.co  m*/
  var x = document.getElementById("mySearch").type;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The type property returns which type of form element the search field is.

For a search field, this property will always return "search".




PreviousNext

Related