Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS - how to remove image with JavaScript?

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

<img src="image.png" id='image_X'>
...
document.getElementById('image_X').src=''

Image stays unchanged :( So my question is how to remove image with JS? To be more detailed... How to modify the image src attribute value dynamically?

Any useful comment is appreciated

like image 930
user592704 Avatar asked Jul 23 '11 19:07

user592704


People also ask

What does remove () do JS?

The JavaScript delete operator removes a property from an object; if no more references to the same property are held, it is eventually released automatically.

How do you remove an element in JavaScript?

Approach: Select the HTML element which need to remove. Use JavaScript remove() and removeChild() method to remove the element from the HTML document.


1 Answers

var image_x = document.getElementById('image_X');
image_x.parentNode.removeChild(image_x);

http://jsfiddle.net/5DdyL/

like image 137
Jared Farrish Avatar answered Sep 16 '22 18:09

Jared Farrish