jquery 10 박스를 클릭하면 박스 크기와 색상이 변경
프론트엔드/Jquery2021. 3. 18. 00:18
박스1
박스2
박스3
박스4
박스5
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
var xWidth=100;
var yHeight=100;
$("div.a").click(function(){
$(this).width(xWidth).addClass("boxii");
$(this).height(yHeight).addClass("boxii");
xWidth=xWidth-10;
yHeight=yHeight-10;
})
});
</script>
<style>
.a{
width:100px;
height:100px;
float:left;
margin:5px;
background:yellow;
}
.boxii{
background: red;
}
</style>
</head>
<body>
<div class="a">박스1</div>
<div class="a">박스2</div>
<div class="a">박스3</div>
<div class="a">박스4</div>
<div class="a">박스5</div>
</body>
</html>
'프론트엔드 > Jquery' 카테고리의 다른 글
jquery 12 이미지 위치와 크기를 변경 (0) | 2021.03.18 |
---|---|
jquery 11 이미지크기를 픽셀 종류별로 변경 (0) | 2021.03.18 |
jquery 09 css() 메소드 (0) | 2021.03.18 |
jquery 07 addClass()와 removeClass()메소드 (0) | 2021.03.18 |
jquery 06 mousedown()와 mouseup() 메소드 (0) | 2021.03.17 |
댓글()