开发者

replaceing innerHTML of div with some html code

开发者 https://www.devze.com 2023-01-31 19:28 出处:网络
I haveadiv with id xyz.Now i have avariable which has some html code like follows var mycode = \"<br>jajaj<b>jjja</b> \";

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 dynamica开发者_开发问答llly created in my code.

if i do simple document.getElementById("xyz").innerHTML ="some text" this works


getElementById() is case sensitive.


You had missed semicolon

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消