Reputation: 157
getElementById does not return any value. My objective is I have a text content and
upon a action I have to replace the value of the text. I use labels to display.
Is there any better way to display such modified text, I dont want to use textbox.
<% for(int i=0; i<lines.length;i++) {
if(lines[i].contains(" ")) { %>
<label id='idkey<%=i%>' name='key1<%=i%>'>ABC</label>
<%
}
} %>
for(j=0; j<len; j++){
var lblElement = document.getElementById('idkey'+j).innerText="ddd";
alert(lblElement);
}
Upvotes: 0
Views: 387
Reputation: 101
The line var lblElement = document.getElementById('idkey'+j).innerText="ddd";
does not set lblElement
equal to the element - but rather equal to the text "ddd"
.
Try the following in stead:
for(j=0; j<len; j++){
var lblElement = document.getElementById('idkey'+j);
lblElement.innerText="ddd";
alert(lblElement);
}
Note: This assumes that the len
variable contains the correct value
Upvotes: 0
Reputation: 635
Re hi,
I think your Id is wrong, innerText work properly with http://jsfiddle.net/mPc2E/ Be carreful, innerText return the value of you new text, not the modified tag.
document.getElementById('lab').innerText = " toto"
Upvotes: 1