javaScript/jQuery
[jQuery]contents() 주석 노드 포함 모든 직계 자식 반환
mooyou
2023. 1. 10. 20:18
728x90
300x250
SMALL
contents()
선택한 요소의 텍스트 및 주석 노드 포함 모든 직계자식을 반환
동일한 도메인에 있는 경우 iframe의 HTML에도 액세스할 수 있다.
$(선택자).contents();
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").contents().filter("em").wrap("<b/>");
});
});
</script>
<div><em>Hello world! What a beautiful day!</em></div>
<p>In this example, by clicking on the button, we search for all the text nodes inside the div element and wrap them with a b element.</p>
<button>div 요소 내부의 em 노드를 찾아 래핑</button><br>
참고 : https://www.w3schools.com/jquery/traversing_contents.asp
728x90
반응형
LIST