웹개발/jQuery

[jQuery] 클래스 조작, hover

hatch 2021. 12. 13. 10:51
728x90
반응형
실행 화면
마우스 올릴 때 마우스 내릴 때

 

 

1. JQuery 코드

<!DOCTYPE html>
<html><head><meta charset="UTF-8">
<title>x</title>
<script src="http://code.jquery.com/jquery-3.4.1.js"></script>
<style>
	#box {width: 100px; height: 100px; background-color: red;}
    #box.hover {background-color: blue; border-radius: 50px;}
</style>
</head>
<body>
<div id="box"></div>
<script>
$(document).ready(function(){
	$("#box").hover(function() {
		$("#box").addClass('hover'); //클래스 추가
	}, function() {
		$("#box").removeClass('hover'); //클래스 삭제
	});
});
</script>
</body>
</html>

 

2. 복습

- hover(올릴 때, 내릴 때); - 2가지 동작을 모두 작성해야 함.