HTML DOM लेबल htmlFor गुण for विशेषता का मान लौटाता/सेट करता है।
सिंटैक्स
निम्नलिखित सिंटैक्स है −
for विशेषता का मान लौटाना −
labelObject.htmlFor
उदाहरण
आइए लेबल htmlFor गुण का एक उदाहरण देखें −
<!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">लेबल 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 = 'लेबल for विशेषता editor one पर सेट है'; labelSelect.htmlFor = 'editorOne'; } } </script> </body> </html>
आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा −
'संपादक बदलें' बटन पर क्लिक करने से पहले −

'संपादक बदलें' बटन पर क्लिक करने के बाद −
