Bartek Lepieszkiewicz Bartek Lepieszkiewicz - 17 days ago 6
jQuery Question

How to make a script on a website that will swap the words?

I have a sited saved on my computer. I would like two buttons to it.

When you press the first one there will appear two text box with 'swap from', 'swap for' and 'make' button at the top of site, and you will need to put words you would like to swap on the site. It should also return how many changes were made and the buttons should disapper after clicking the make button.

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.

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

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>
Comments