특정 요소에 클릭 이벤트를 적용
[Click.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>bind() 중 click 이벤트는 click()메서드로 사용</title>
<style type="text/css">
.redColor { color:Red; }
</style>
<script src="js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
// 특정 요소에 클릭 이벤트를 적용 : bind()보다 간편
$('#mainMenu .redColor').click(function() {
if (this.id == "dnk") {
location.href = "http://www.dotnetkorea.com";
}
else if (this.id == "va") {
window.open("http://www.VisualAcademy.com/", "", "");
}
});
});
</script>
</head>
<body>
<div id="mainMenu">
<div id="dnk" class="redColor">닷넷코리아</div>
<div id="va" class="redColor">비주얼아카데미</div>
<div id="ll" class="redColor">라이선스랜드</div>
</div>
</body>
</html>
-------------------------------------------------------------------------------------
[실행결과]
--> 첫 화면
--> 위의 그림에서 '닷넷코리아'텍스트를 클릭하면 해당사이트로 이동함.
--> 맨 위의 그림에서 '비주얼아카데미'텍스트를 클릭하면 또 하나의 '인터넷 창'이 열리면서 해당사이트로 이동함.