IT/프론트엔드
[jquery기초]jquery를 활용하여 width,height 변경하기(클릭할때마다 커지는 my-div)
삥뽕뺑뽕
2023. 1. 13. 00:21
안녕하세요 오늘은 jquery를 이용하여 클릭할때마다 화면이 바뀌는 상황을 연출해볼게요.
매우 간단한 코드이니 설명은 주석으로 대체합니다.
<!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>
<style>
#my-div{
width: 100px;
height: 100px;
background-color:pink;
}
</style>
<script src="./js/jquery.min.js"></script>
<script>
function myFunc(){//클릭시 작동되는 함수
$("#my-div").css({//id my-div를 지정
"width":"+=50px",//클릭시 원래 width값에 50px를 더함
"height":"+=50px"//클릭시 원래 height값에 50px를 더함
})
}
</script>
</head>
<body>
<div id="my-div">
내 div
</div>
<button onClick="myFunc()">클릭</button>
</body>
</html>