0

At first I wanted to hide all the body and show only one image, but it seems that it's not possible since hiding the body with display:none would hide all of it's children. So I changed my code to just hiding the parameters I want to hide.

At Bottom line: I want to show the hidden content when I click on the content that is not hidden.

Here is my HTML Code enter image description here js code is enter image description here And finally css code is enter image description here

Even the code looks very simple but i'm struggling: when I click on the image, nothing happens.

I'm absolutely sorry if my question is not very well formulated, this is my first question on stackoverflow and I will be glad to make it more clear. Thank in advance.

2
  • 1
    please add the code in text form to the question. you may use the power of <>, where you get a small IDE. Commented Jan 26, 2019 at 13:01
  • You are using .style.display=block, that should be the string "block", the quotes are important. (Your code as it is should be throwing an error, always look in the console when things don't work as expected.) Commented Jan 26, 2019 at 13:07

3 Answers 3

1

You have an error in JS, you have to use quotations marks.

... .style.display = "block";

Sign up to request clarification or add additional context in comments.

Comments

0

<html>
<head>
    <style>
        p {
            display: none;
        }
    </style>
</head>
<body>
    <p>This is some random text</p>
    <img id="click" src="" width="500px" height="500px">

    <script>
        var toggle = document.getElementById("click");
        toggle.addEventListener("click", show);

        function show() {
            var p = document.getElementsByTagName("p")[0].style.display = "block";
        }
    </script>
</body>
</html>

Comments

0

Thank you all for your support! I've actually found the answer. I was facing some problems with getElementsByTagName and getElementsByClassName since you actually had to use the for loop to display all of the elements. So I just used getElementById and used the "onclick" event in the HTML code. Thanks!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.