Entry
How do I change the content of a LEGEND?
May 7th, 2000 07:27
Martin Honnen,
The following assumes the content is text:
<HTML>
<HEAD>
<SCRIPT>
function changeLegend (id, text) {
if (document.all)
document.all[id].innerText = text;
else if (document.getElementById) {
var l = document.getElementById(id);
l.normalize();
l.firstChild.nodeValue = text;
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName">
<FIELDSET>
<LEGEND ID="aLegend">
JavaScript.FAQTs.com
</LEGEND>
<INPUT TYPE="text" NAME="aField" VALUE="Kibology">
<INPUT TYPE="checkbox">
<BR>
<INPUT TYPE="button" VALUE="change legend"
ONCLICK="changeLegend('aLegend', this.form.aField.value)"
>
</FIELDSET>
</FORM>
</BODY>
</HTML>
If you want to assign html content use
<HTML>
<HEAD>
<SCRIPT>
function changeLegend (id, html) {
if (document.all)
document.all[id].innerHTML = html;
else if (document.getElementById) {
var l = document.getElementById(id);
while (l.hasChildNodes())
l.removeChild(l.lastChild);
var r = document.createRange();
r.setStartAfter(l);
var docFrag = r.createContextualFragment(html);
l.appendChild(docFrag);
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName">
<FIELDSET>
<LEGEND ID="aLegend">
JavaScript.FAQTs.com
</LEGEND>
<INPUT TYPE="text" NAME="aField" VALUE="Kibology<IMG
SRC=kiboInside.gif>">
<INPUT TYPE="checkbox">
<BR>
<INPUT TYPE="button" VALUE="change legend"
ONCLICK="changeLegend('aLegend', this.form.aField.value)"
>
</FIELDSET>
</FORM>
</BODY>
</HTML>