Javascript DOM HTML Input Radio autofocus Property get

Introduction

Find out if a radio button automatically gets focus on page load:

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

Click the button to find out if the radio button automatically gets focus on page load.

View in separate window

<!DOCTYPE html>
<html>
<body>

Radio Button: <input type="radio" id="myRadio" autofocus>
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {//from  w  ww  .  j  av a2  s  .  co  m
  var x = document.getElementById("myRadio").autofocus;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The autofocus property sets or gets whether a radio button should get focus on page load.

This property mirrors the HTML autofocus attribute.

Value Description
true The radio button gets focus
falseDefault. The radio button does not get focus

The autofocus property returns true if the radio button automatically gets focus on page load, otherwise it returns false.




PreviousNext

Related