Show/hide image with JavaScript

后端 未结 6 644
抹茶落季
抹茶落季 2020-12-08 15:17

I have an HTML page with an image that I set to be invisible by CSS visibility: hidden. I want to make a link called \"Show image\", so that when I click on it,

6条回答
  •  伪装坚强ぢ
    2020-12-08 15:27

    If you already have a JavaScript function called showImage defined to show the image, you can link as such:

    show image
    

    If you need help defining the function, I would try:

    function showImage() {
        var img = document.getElementById('myImageId');
        img.style.visibility = 'visible';
    }
    

    Or, better yet,

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

    Then, your links would be:

    show image
    hide image
    

提交回复
热议问题