목차
:parent 예제 - 안 비어있는 TD 배경색 변경 :parent 정의 :parent 구문
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("td:parent").css("background-color", "yellow"); }); </script> <table border="1"> <tr> <th>사이트명</th> <th></th> <th>오픈년도</th> </tr> <tr> <td></td> <td>Homzzang.com</td> <td>2012</td> </tr> </table> 결과보기
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("td:parent").css("background-color", "yellow");
});
</script>
<table border="1">
<tr>
<th>사이트명</th>
<th></th>
<th>오픈년도</th>
</tr>
<td></td>
<td>Homzzang.com</td>
<td>2012</td>
</table>
결과보기
※ 빈 td 셀에 글자 입력하면 배경색이 노랗게 변함.
텍스트 노드 포함해 다른 요소의 부모인 모든 요소 선택. 즉, 요소 안에 (텍스트/타 요소)가 있는 모든 요소 선택. cf. :empty 선택자 : 비어있는 요소 선택. :contains() 선택자 - 지정 문자열 포함 요소 선택. :has() 선택자 - 지정 요소 포함 요소 선택.
텍스트 노드 포함해 다른 요소의 부모인 모든 요소 선택.
즉, 요소 안에 (텍스트/타 요소)가 있는 모든 요소 선택.
cf.
$(":parent")