MelonPeach

10. jquery Method [ .click() ] - 선택한 요소를 클릭했을 때 특정 작업을 수행하는 메소드

 

문법


.click(handler)

 

예를 들어

 

$("button").click(function(){

})

 

button을 클릭했을 때  작업을 수행합니다.


 

 

 

예제 코드


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
	<head>
		<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
		<title>Home</title>
	</head>
	<script type="text/javascript">
    $(document).ready(function(){
    	$("button").click(function(){
    		$("button").css("color", "red");
    	})
    });
	</script>
	<body>
		<button>버튼</button>
	</body>
</html>

 

버튼을 클릭했을 때 버튼 내용의 color을 red로 바꿉니다.


 

 

 

실행 테스트


See the Pen 12 by youngjins (@youngjins) on CodePen.

이 글을 공유합시다

facebook twitter googleplus kakaostory naver