BIS601 Program 4

  • Open index.html file in vscode and copy the below code paste it into that file, save it.

PROGRAM:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Event Listeners Example</title>
    <style>
        img {
            width: 200px;
            height: 140px;
            border: 5px solid black;
            margin-top: 10px;
        }

        button {
            padding: 5px 10px;
            background: #000;
            color: #fff;
            border-radius: 5px;
            cursor: pointer;
        }
    </style>
</head>

<body>

    <button id="myButton">Click Me</button><br>

    <img id="myImage" src="https://vtucircle.com/wp-content/uploads/2025/01/Full-Stack-Development-BIS601.jpg">

    <script>
        const button = document.getElementById('myButton');
        button.addEventListener('click', function () {
            console.log('Button clicked!');
        });

        const image = document.getElementById('myImage');
        image.addEventListener('mouseover', function () {
            image.style.borderColor = 'red';
        });

        document.addEventListener('keydown', function (event) {
            console.log('Key pressed: ' + event.key);
        });
    </script>
</body>

</html>

Step 2: To run program

  • Install live server extension to see the visual output (It’s recommended).

OUTPUT:

output 4
output 4
output 4
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x