JS - how to remove image with JavaScript?

前端 未结 9 1372
孤独总比滥情好
孤独总比滥情好 2021-02-13 11:27

I faced a problem as to remove image with JS code like a...


...
document.getElementById(\'image_X\').src=\'\'
         


        
9条回答
  •  余生分开走
    2021-02-13 12:08

    You could just hide it. In vanilla JS that would be:

    document.getElementById("image_X").style.display='none';
    

    In jQuery:

    $("#image_X").css('display', 'none');
    

    If you really want to remove it from DOM, there is removeChild method you could invoke on the parentNode of your image element.

提交回复
热议问题