JS - how to remove image with JavaScript?

前端 未结 9 1381
孤独总比滥情好
孤独总比滥情好 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:15

    I want to share some additional tips...

    @Marecky, Thank to Jared Farrish answer I could figure out some helpful points concerning JS...

    But next I had to make my own additional research as well... It is not a super fact, but a little theory tip... So, as a result, I could find that browsers, as a any desktop app, of course, are created with some kind of GUI framework... As a rule, most GUI (for example Swing) frameworks, of course, may using double buffered objects to display graphics... So when it (FF for example) re-translates script to graphic objects the GUI sync rules come to life...

    ...OK... Coming from GUI re-painting problems to scripting itself...

    So my question was about playing around DOM objects... The fact was the img tag doesn't update UI event if the code like document.getEelementById('image_X').src='' is activated; So the tag space (for some reason) , I am not sure but, is keeping some kind of 'cached' state... And maybe that makes img (if it is in body) become 'static'; So I had to find some helpful additional object which supports dynamic UI update. As a test, I used div instead of the pure body tag to keep img in it; So not to update body but div inner content only and that helped. So using JS + HTML in my case was helpful...

    I hope the tip saves ones day

提交回复
热议问题