How to display image after clicked button using JavaScript?

0 votes
38 views
Ravi Vishwakarma asked 11 days ago in Web Application by Ravi Vishwakarma

How to display image after clicked button using JavaScript?

1 Answer

1 votes
Ethan Karla answered 8 days ago by Ethan Karla
<!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>