Javascript DOM HTML Input Color autofocus Property get

Introduction

Find out if a color picker automatically gets focus upon page load:

var x = document.getElementById("myColor").autofocus;

Click the button to find out if the color picker automatically gets focus when the page loads.

View in separate window

<!DOCTYPE html>
<html>
<body>

A color picker: <input type="color" id="myColor" autofocus>
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {//from   w w  w  . j av a 2s  . c  om
  var x = document.getElementById("myColor").autofocus;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The autofocus property sets or gets whether a color picker can automatically get focus on page loading, or not.

This property mirrors the HTML autofocus attribute.

The autofocus property accepts and returns a boolean value.

Value Description
trueThe color picker gets focus
false Default. The color picker does not get focus



PreviousNext

Related