DEV Community

gotheer
gotheer

Posted on

DOM manipulation

This is how to get off innerHTML and use textContent instead keeping the power that innerHTML offers
< p id="output"></ p >

      let a = newEl("em");
      let b = newEl("strong");
      let c = newEl("span");
          a.textContent = "I ";
          b.textContent = "love ";
          c.textContent = "javascript";
          c.style.cssText = "color: red;";
             let d = document.querySelector("#output");
                      d.appendChild(a);
                       d.appendChild(b);
                        d.appendChild(c);
function newEl(el){
  return document.createElement(el);}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)