Javascript Reference - HTML DOM Input Color autofocus Property








The autofocus property sets or gets whether a color picker can automatically get focus when the page loads.

Browser Support

autofocus Yes No Yes No Yes

Syntax

Return the autofocus property.

var v = colorObject.autofocus 

Set the autofocus property.

colorObject.autofocus=true|false

Property Values

Value Description
true|false Set whether a color picker can get focus when the page loads
  • true - The color picker gets focus on page loading
  • false - Default. The color picker does not get focus on page loading




Return Value

A Boolean type value, true if the color picker can automatically get focus when the page loads, otherwise it returns false.

Example

The following code shows how to get if a color picker automatically gets focus.


<!DOCTYPE html>
<html>
<body>
<!-- w ww  .  jav a2s.c o  m-->
A color picker: <input type="color" id="myColor" autofocus>
<button onclick="myFunction()">test</button>
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myColor").autofocus;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: