Home > Back-end >  I want to select my created parent element and prints to console
I want to select my created parent element and prints to console

Time:06-27

I want to select this div and prints to console i tried this but not working

let divList = document.createElement('div')
    divList.setAttribute("id","container")
    parentEl.appendChild(divList)
    console.log(document.getElementbyId('container')

CodePudding user response:

You have a typo it's "getElementById" not "getElementbyId";

let divList = document.createElement('div');

divList.setAttribute("id", "container");
parentEl.appendChild(divList);

console.log(document.getElementById('container'));
  • Related