TAG
JavaScript
Result
Run
License
<h3>Click to the item.</h3> <ul id="list"> <li title="사과">Apple</li> <li title="바나나">Banana</li> <li title="당근">Carrot</li> </ul>
window.addEventListener("load", function() { [...document.querySelectorAll("#list > li")].forEach(item => { item.addEventListener("click", e => { let that = e.currentTarget; let newNode = document.createElement("li"); newNode.textContent = that.getAttribute("title"); let oldNode = that.parentElement.replaceChild(newNode, that); console.log(oldNode.textContent); }); }); });
Console
expand_less
License
License
by DevDic
Close