Reputation: 71
I have a div with id xyz.Now i have avariable which has some html code like follows
var mycode = "<br>jajaj<b>jjja</b> ";
Now i want to replace content of div with this html code by using following
document.getElementbyid("xyz").innerHTML = mycode
This doenot work.I am not getting why.mycode is dynamicallly created in my code.
if i do simple document.getElementById("xyz").innerHTML ="some text"
this works
Upvotes: 1
Views: 8731
Reputation: 2946
Have you type your code in this manner?
<html>
<body>
<div id="xyz"></div>
<script>
var mycode = "<br>jajaj<b>jjja</b> ";
document.getElementById("xyz").innerHTML = mycode;
</script>
</body>
</html>
This one worked for me. Please post your sample code so that we can see it.
Upvotes: 0
Reputation: 8463
You had missed semicolon
document.getElementbyid("xyz").innerHTML = mycode;
Upvotes: 0