How to display image after clicked button using JavaScript?

Asked 19-Jul-2021
Viewed 614 times

0

How to display image after clicked button using JavaScript?


Comment
This is test comments. - Ravi Misra19-Jan-2023

1 Answer


1

<!DOCTYPE html>

<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title></title>
    <style>
    img{
        box-sizing:border-box;
        width:40%;
        height:auto;
        display:none;
        padding:5px;
        }
        button {
            width:100px;
            height:30px;
        }
    </style>
</head>
<body>
    <img src='wood2.jpg' id='image'/>
    <button onclick='showImage()'>Show Image</button>
    <button onclick='hideImage()'>Hide Image</button>
    <script>
        function showImage() {
            document.getElementById('image').style.display = 'block';
        }
        function hideImage() {
            document.getElementById('image').style.display = 'none';
        }
    </script>
</body>
</html>