0

Is it possible to put an innerHTML (or style.) Variable in DOM javascript? If not, is there a trick to making this possible?

In the following example:

<h1 id="id01">Old Heading</h1>
var element = document.getElementById("id01");
var newinner = "innerHTML";
element.newinner = "New Heading";
  • 1
    you can use the bracket object property notation, `element[newinner] = ...` when needing to use a variable for a property name – Patrick Evans May 15 '21 at 09:00
  • I geting Unexpected token '[' – aldin_abdagic May 15 '21 at 09:02
  • If you want to keep it simple, you could use `` Make sure your add it at the end of your HTML file, before the

    TAG.

    – Mike de Bie May 15 '21 at 09:09
  • 1
    Thx Mike de Bie, but I need in the way described. I managed to remove the dot after style and now it works. If Patrick Evans can answer the question I put mark as an answer – aldin_abdagic May 15 '21 at 09:15

0 Answers0