<style type="text/css">
.css_test span {
border-radius : 5px;
border : 5px solid gray;
padding : 7px;
}
</style>
<div class="css_test">
jQuery 공작소에 방문해 주셔서 감사드립니다.
<br><br>
닭 <img src="//superkts.com/img/css/bird17.gif" />
</div>
<button type="button"
onclick="j_test()">버튼을 눌러보세요.</button>
<script type="text/javascript">
function j_test(){
$( '.css_test' )
.contents()
.filter(function() {
return this.nodeType === 3;
})
.wrap('<span>');
}
</script>
- contents 메서드는 내용을 객체형태로 가져오므로 원하는 처리를 더 편하게 할 수 있습니다.
- 닭 뒤에 빈 네모칸(span)이 생기는 이유는 뒷쪽에 있는 "엔터" 도 텍스트이기 때문입니다.