javascript&jquery
[Jquery] element 내용 비우기 empty()
pm1122Dev
2021. 4. 26. 22:45
728x90
반응형
.empty() | jQuery API Documentation
This method removes not only child (and other descendant) elements, but also any text within the set of matched elements. This is because, according to the DOM specification, any string of text within an element is considered a child node of that element.
api.jquery.com
제이쿼리에서 html 태그를 삭제하는 것이 아닌 태그안에 있는 내용을 지워야할 경우가 있습니다.
그럴경우 empty() 함수를 사용합니다.
예를 들면
html
<ul>
<li>과자</li>
<li>과일</li>
<li>음료</li>
<li>커피</li>
</ul>
jqeury
$(function(){
$("li").empty();
})
결과
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
728x90
반응형