filter() 메서드를 사용해서 조건에 맞는 요소만 가져오기
.NET프로그래밍/jQuery 1.3.2 2009. 11. 6. 11:04 |[Filter.htm]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>filter() 메서드를 사용해서 조건에 맞는 요소만 가져오기</title>
<style type="text/css">
.redBorder { border:solid 1px red; }
.five { border-width:5px; }
</style>
<script src="js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('img').addClass('redBorder') // 모든 이미지에 redBorder 클래스 적용
.filter('[title*=닷넷]').addClass('five') // '닷넷' title만 뽑아서 five 클래스 적용
.end() // 부모로 이동
.filter('[alt$=디드]').removeClass('redBorder'); // '디드'로 끝나는 스타일 제거
});
</script>
</head>
<body>
<img src="" title="닷넷" alt="닷넷" />
<img src="" title="자바" alt="자바" />
<img src="" title="임베디드" alt="임베디드" />
</body>
</html>
<!--
파이어폭스에서는 이미지(image)가 깨질경우 브라우저에 이미지가 출력이 안되므로, '이미지'가 깨지면 이미지를 대신할 '대체텍스트'를 넣어주는게
기본(기본값)이다.
-->
-------------------------------------------------------------------------------------
[실행결과]
'.NET프로그래밍 > jQuery 1.3.2' 카테고리의 다른 글
toggle() 메서드로 토글링 (0) | 2009.11.06 |
---|---|
slice() 메서드로 지정된 개체만 가져오기 (0) | 2009.11.06 |
특정 요소에 클릭 이벤트를 적용 (0) | 2009.11.06 |
This.id로 DOM 요소의 id 속성 가져오기 (0) | 2009.11.06 |
AddClass / RemoveClass(스타일 추가 / 제거) (0) | 2009.11.06 |