1

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

4
  • 5
    try with getElementById javascript is key sensitive Commented Dec 21, 2010 at 9:23
  • i cant see output of mycode in div Commented Dec 21, 2010 at 9:30
  • 2
    try to post some more codes. is necessary for problem Commented Dec 21, 2010 at 9:34
  • posted a sperate question for it stackoverflow.com/questions/4499221/… Commented Dec 21, 2010 at 12:30

3 Answers 3

5

getElementById() is case sensitive.

Sign up to request clarification or add additional context in comments.

5 Comments

@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?
if i do document.EetElementById("xyz").innerHTML ="some text" it works fine
@akshay - you need to post the entire code block, not fragments for this to progress.
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.
am using dojo and there is some variable scoping problem with dojo ,iposted aseperate question for this stackoverflow.com/questions/4499221/…
0

You had missed semicolon

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

1 Comment

This is very unlikely to be it. An implicit semi-colon will be inserted here unless the fucntion was particularly badly formatted.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.