0

I have an issue that I've never encountered before. I would like simply to add a div inside another. I test using the developer console first. I get the element in which I want to include the another div and it prints the element correctly in the console. Then I do the following:

document.getElementById("ctiGlobalContainer").innerHtml += '<div id="ctiContentPanel" state="displayed" style="z-index: 10000;right: 0;top: 50px;height: 100%;width: 200px;position: fixed;margin: 0;"></div>'

I get the following result:

"undefined<div id="ctiContentPanel" state="displayed" style="z-index: 10000;right: 0;top: 50px;height: 100%;width: 200px;position: fixed;margin: 0;"></div>"

Why is the undefined showing ? And the div is not included in the dom...

Hubert Solecki
  • 2,611
  • 5
  • 31
  • 63
  • It's not a best way to add HTML in your page with innerHTML, use jQuery or, see `.appendChild()` function : http://stackoverflow.com/questions/14004117/create-div-and-append-div-dynamically – user2226755 Dec 15 '16 at 10:01

2 Answers2

2

The property is called innerHTML.

innerHtml starts out undefined.

+= converts that to a string and then appends to it.

When you convert undefined to a string you get "undefined".

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

You have typo in there. Please instead of innerHtml use innerHTML. Javascript is not recognizing innerHtml as its property that is why the code in there is showing undefined.

Yubaraj Shrestha
  • 864
  • 1
  • 10
  • 16