웹/제이쿼리 JSTL
제이쿼리 -요소 찾기/ 봐도봐도 까먹는 선택자 (next,prev,parent,children,siblings,>,+)
은은하게미친자
2023. 1. 5. 10:44
728x90
1. 인접관계 선택자
: 선택한 요소와 가까이에 있는 요소를 선택 할때 사용
<script> $(function(){ $("h2").next().val(); $("h2").parent().val(); }); </script> |
parent() : 부모
children() : 자식
prev() : 형, 이전
next() : 동생 , 다음
siblings() : 나를 제외한 형제요소들 ex) $('.tabs > ul > li').siblings().length 형제요소 개수 가져오는법
$("요소1 + 요소2") : 요소1 기준 바로 다음에 오는 선택한 요소2만 선택
2. 하위 선택자
<script> $(function(){ $("#title h2").css({"background-color":"yellow", "border":2px}); }); </script> |
: id 가 title 인 모든 h2 변경
3. 자식선택자 (>, children, childred)
<script> $(function(){ $("#tablediv > ul > li").css({"background-color":"yellow", "border":2px}); $("#tablename > h2l").children().css({"background-color":"yellow", "border":2px}); }); </script> |
728x90