.innerHTML is not a function [duplicate]
Asked Answered
P

2

5

Its so plain simple, I can not comprehend, what is the issue? All DOMs are created before I pick them, used either a document.getElementsByClass or just the dom object created itself, not working... I wonder where did I do wrong?

    var wrapperDom = document.createElement('div');
    wrapperDom.className = 'sticky-state-wrapper';

    var containerDom = document.createElement('div');
    containerDom.className = 'sticky-state-container';

    var targetDom = document.createElement('div');
    targetDom.className = 'sticky-state-target';
    targetDom.style.height='50px';
        targetDom.innerHTML("My Sticky Component");

https://jsfiddle.net/adamchenwei/cv3mpL4k/1/

Pettifog answered 18/4, 2016 at 20:2 Comment(3)
Well, innerHTML is not a function... developer.mozilla.org/en-US/docs/Web/API/Element/innerHTMLCracking
should be targetDom.innerHTML = "My Sticky Component";Humpbacked
try targetDom.innerHTML="My Sticky Component";Consols
D
20

It's not a function. It's a property. Try this instead:

targetDom.innerHTML = "My Sticky Component";
Dahlberg answered 18/4, 2016 at 20:4 Comment(0)
P
3

That's because, like elclanrs said, innerHTML is not a function.

Use it like this: targetDom.innerHTML = "My Sticky Component";

Polarity answered 18/4, 2016 at 20:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.