본문 바로가기
Coding/HTML & CSS

[HTML & CSS] div 태그에 onclick 기능 주는 방법 !! (클릭 이벤트)

by 포스트it 2023. 1. 16.
728x90
반응형

[HTML & CSS] div 태그에 onclick 기능 주는 방법 !! (클릭이벤트)

 

아래 코드 참조해서 사용하시면 됩니다 :)

<!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>
</head>
<style>
.div1 {
    width: 300px;
    height: 100px;
    border: 1px solid blue;
    background-color:#384E80;
}

.div1:hover {
    background-color:#0a5021;
}
</style>

<body>

    <div class='div1' onclick='divBtn();'></div>

</body>
</html>

<script>

function divBtn() {
    alert('클릭 이벤트 입니다 !!');
}

</script>

결과값

 

728x90
반응형

댓글