Da salida indefinida para ambos. Debería generar lpoop y /poop. No se dan errores
function add() { console.log("add") var l = document.createElement("img") l.setAttribute("src", "/poop") l.src = "/poop" l.setAttribute("class", "l") l.className = "lpoop" document.getElementById("b").appendChild(l) } function find() { console.log("find"); const elm = document.getElementById("b").firstChild; console.log(elm.className); console.log(elm.src); } <button onclick="add()"> hi </button> <button onclick="find()"> find </button> <div id="b"> </div>Si hay más detalles que desee, por favor comente.
function add() { console.log("add") var l = document.createElement("img") l.setAttribute("src", "/poop") l.setAttribute("class", "l") document.getElementById("b").appendChild(l) } function find() { console.log("find"); const elm = document.getElementById("b").firstChild; console.log(elm.getAttribute("src")); console.log(elm.getAttribute("class")); } <button onclick="add()"> hi </button> <button onclick="find()"> find </button> <div id="b"></div> Cuando usa elem.attr , significa que está obteniendo el atributo JS del elemento, no el atributo HTML.
La función .getAttribute() obtendrá el atributo HTML.