HTML for एट्रिब्यूट <label> एलिमेंट को पहले लेबल करने योग्य एलिमेंट से बांधता है जिसकी id for एट्रिब्यूट के मान के समान होती है।
सिंटैक्स
निम्न सिंटैक्स है:
1. for एट्रिब्यूट का मान प्राप्त करना:
labelObject.htmlFor
उदाहरण
आइए for एट्रिब्यूट का एक उदाहरण देखते हैं:
<!DOCTYPE html> <html> <head> <title>Label htmlFor</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } </style> </head> <body> <form> <fieldset> <legend>Label-htmlFor</legend> <label id="CurrentEditor" for="editorTwo">वर्तमान संपादक:</label><br> <input type="text" id="editorOne" placeholder="editorOne"> <input type="text" id="editorTwo" placeholder="editorTwo"> <input type="button" onclick="getEventData()" value="संपादक बदलें"> <div id="divDisplay">Label for एट्रिब्यूट editor two पर सेट है</div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var labelSelect = document.getElementById("CurrentEditor"); function getEventData() { if(labelSelect.htmlFor === 'editorTwo'){ divDisplay.textContent = 'Label for एट्रिब्यूट editor one पर सेट है'; labelSelect.htmlFor = 'editorOne'; } } </script> </body> </html>
यह निम्न आउटपुट देगा:
1) 'संपादक बदलें' बटन पर क्लिक करने से पहले:

2) 'संपादक बदलें' बटन पर क्लिक करने के बाद:
