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
3 Answers 3
getElementById() is case sensitive.
answered Dec 21, 2010 at 9:25
alex
492k205 gold badges891 silver badges992 bronze badges
Sign up to request clarification or add additional context in comments.
5 Comments
alex
@akshay It worked for me. Your
mycode is probably not in the right scope. Can you please post more code? What does alert(mycode) popup with just before you attempt to set the innerHTML property?akshay
if i do document.EetElementById("xyz").innerHTML ="some text" it works fine
annakata
@akshay - you need to post the entire code block, not fragments for this to progress.
OnesimusUnbound
I've tried the code: mycode = "<br>jajaj<b>jjja</b> "; document.getElementById("xyz").innerHTML = mycode; and it worked. I used Firebug lite to test it. Could you post all the statements in one place? It could be scope issue.
akshay
am using dojo and there is some variable scoping problem with dojo ,iposted aseperate question for this stackoverflow.com/questions/4499221/…
You had missed semicolon
document.getElementbyid("xyz").innerHTML = mycode;
answered Dec 21, 2010 at 9:33
Mohan Ram
8,47125 gold badges86 silver badges132 bronze badges
1 Comment
annakata
This is very unlikely to be it. An implicit semi-colon will be inserted here unless the fucntion was particularly badly formatted.
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.
answered Dec 21, 2010 at 9:40
OnesimusUnbound
2,9463 gold badges30 silver badges40 bronze badges
Comments
default
getElementByIdjavascript is key sensitive