Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
153
rated 0 times [  155] [ 2]  / answers: 1 / hits: 23572  / 15 Years ago, thu, september 17, 2009, 12:00:00

What JavaScript will remove all image tags?


More From » javascript

 Answers
42

UPD: sorry, this is a wrong answer, see comments. This is a correct answer.



Something like this:



images = document.getElementsByTagName('img');
for (i = 0; i < images.length; i++) {
images[i].parentNode.removeChild(images[i]);
}




OR a slight modification of my first attempt to answer this question:



var images = document.getElementsByTagName('img');
var l = images.length;
for (var i = 0; i < l; i++) {
images[0].parentNode.removeChild(images[0]);
}

[#98676] Monday, September 14, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alonso

Total Points: 747
Total Questions: 108
Total Answers: 105

Location: Mauritania
Member since Sun, Sep 25, 2022
2 Years ago
;