Javascript DOM HTML Input Color form Property get

Introduction

Get the id of the form containing the <input type="color"> element:

var x = document.getElementById("myColor").form.id;

Click button to display the form id the color picker belongs to.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm">
  A color picker: <input type="color" id="myColor">
</form>/*  ww  w.  ja  v a 2  s. co m*/
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

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

</body>
</html>

The form property returns a reference to the form containing the color picker.

This property returns a form object on success.

This property is read only.

If the color picker is not in a form, null is returned




PreviousNext

Related