Search code examples
javascriptappendchildcreateelement

I want to select my created parent element and prints to console


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

Solution

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