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'));