akshay
akshay

Reputation: 71

replaceing innerHTML of div with some html code

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

Answers (3)

OnesimusUnbound
OnesimusUnbound

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

Mohan Ram
Mohan Ram

Reputation: 8463

You had missed semicolon

 document.getElementbyid("xyz").innerHTML = mycode; 

Upvotes: 0

alex
alex

Reputation: 490647

getElementById() is case sensitive.

Upvotes: 5

Related Questions