Bartek Lepieszkiewicz Bartek Lepieszkiewicz - 24 days ago 8
HTML Question

How to make a script that will turn off all photos on the site?

EDIT: I've asked too many questions so I will just leave the part which was
solved in comment.


The second concern is another button that will disable all the photos that are on the site to be seen by te user. When you press it again, the photos will be seen again. SOLVED

I assume it should be done in Javascript, but I'm just starting with learning it, so any help would be much appreciated.

I would like to add functionality to my page.

Answer

I have not fully understand the behavior of the first button. The second button is pretty simple: just make a script that fetches all the images in the page and sets them to display="none";

<script>
var toggle = true;

function imagesToggle(){
    var images = document.getElementsByTagName('img'); 
    if(toggle == true){
        for(var i = 0; i < images.length; i++) {
            images[i].style.display="none";
        }
        toggle = false;
    }
    else{
            for(var i = 0; i < images.length; i++) {
            images[i].style.display="block";
        }
        toggle = true;
    }
}
</script>

And in the button, add the onclick property:

<button onclick="imagesToggle()">Click on me</button>