js how to hide an image 1

js how to hide an image

function setImageVisible(id, visible) {
    var img = document.getElementById(id);
    img.style.visibility = (visible ? 'visible' : 'hidden');

Here is what the above code is Doing:
1. It’s creating a function called setImageVisible.
2. It’s taking two parameters: id and visible.
3. It’s getting the image by id.
4. It’s setting the visibility of the image to visible or hidden.

Now, let’s call this function from the HTML.

js how to hide an image 2

Similar Posts