lastElementChild 예제
<ul id="hz"> <li>홈짱닷컴</li> <li>Homzzang.com</li> </ul> <button onclick="homzzang()">클릭</button> <p id="demo"></p> <script> function homzzang() { var last = document.getElementById("hz").lastElementChild.innerHTML; document.getElementById("demo").innerHTML = last; } </script> 결과보기
<ul id="hz">
<li>홈짱닷컴</li>
<li>Homzzang.com</li>
</ul>
<button onclick="homzzang()">클릭</button>
<p id="demo"></p>
<script>
function homzzang() {
var last = document.getElementById("hz").lastElementChild.innerHTML;
document.getElementById("demo").innerHTML = last;
}
</script>
결과보기