Modify The Text Of My Radio Input Button?
Your average radio button has a name and value, but also some text next to it, in this case 'Change this text.' How can I change this in javascript? Or even alert it? AFAIK, it is
Solution 1:
You could use alert(confirmIExist[0].nextSibling.textContent)
, but wouldn't it be better to place the text next to the radio button in a <label>
and then get the inner html of that
<input type="radio" id="radioOption1" name="radioOption1" value="Array 1"><labelfor="radioOption1"id="r1option">Change this text</label>
...
var label = document.getElementById("r1option");
alert(label.innerHTML);
Solution 2:
You cannot set inner html for a input element. instead wrap your text with a and give it a ID
<input type="radio" name="radioOption1" value="Array 1"> <label id="radioText">Change this text</label>
Solution 3:
input
is a self-closing element. It cannot have innerHTML
nextSibling
will return the Node that follows the radio button.
document.getElementsByName('radioOption1')[0].nextSibling.nodeValue = 'Text changed';
Solution 4:
confirmIExist[0].nextSibling.textContent="abc"
Post a Comment for "Modify The Text Of My Radio Input Button?"