0

So I have to solve a question I got from class. I have to write an init() function in JS for the

elements to be visible or hidden with a click of a button. What I came up is: (which dosen't work). Note: I cannot change the HTML code; add id/class to an element.


<body>
        <p>Lorem ipsum dolor sit </p>
        <p>Lorem ipsum dolor sit </p>
        <p>Lorem ipsum dolor sit </p>
    

    <input type="button" onclick="init()" value="Show/Hide">
    
    <script>
        let x = document.getElementsByTagName("body");
        

        if(x.style.display === 'block') {
            x.style.display = 'none';
            
        } else {
            x.style.display = 'block';
            
        }
    </script>
</body>

Ali P
  • 11
  • 1

0 Answers0