JavaScript Reference/Javascript Properties/htmlFor
"htmlFor" Example
<source lang="javascript">
<html> <body> <script language="JavaScript">
function goFocus() { alert(document.all.myL.htmlFor); }
</script> <script id="myScript" for="myButton2" event="onclick">
alert(myScript.htmlFor);
</script>
<label id="myL" for="myButton"> </label>
<button id="myButton" onclick="goFocus();">HTML for Label</button> <button id="myButton2">HTML for Script</button> </body> </html>
</source>
"htmlFor" is applied to
<source lang="javascript">
+----------------+--------------------------------------------------------------+ | Applied_To |<label> <script> | +----------------+--------------------------------------------------------------+
</source>
"htmlFor" Syntax and Note
<source lang="javascript">
Note: Read and write property. Specifies the element id assigned to <label> or <script>. This property is equivalent to the "for" attribute.
Syntax:
document.getElementById("labelID").htmlFor = value document.all.labelID.htmlFor = value // IE only
</source>