Reputation: 5942
I am trying to retrive html of a dom element "abc".
<div id=abc>
<input id=xyz type=text value="2" />
</div>
<input type=button value="2" onclick="show()"/>
<script>
document.getElementById("xyz").value=5;
function show(){
alert(document.getElementById("abc").innerHTML);
}
</script>
Lets say I modified the value of text box
by Javascript code
document.getElementById("xyz").value=5;
but
alert(document.getElementById("abc").innerHTML);
always show me
<input id=xyz type=text value="2" />
Why? Can anyone tell me how I can get the latest html of the dom element "abc".?
Upvotes: 1
Views: 2847
Reputation: 732
.value will not change the HTML. If you want to do that, use .setAttrubute instead. See this JSFiddle: http://jsfiddle.net/5EFXN/
document.getElementById("xyz").setAttribute('value','5');
Upvotes: 2