Closed Thread Icon

Topic awaiting preservation: Removing an image from a page (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=22468" title="Pages that link to Topic awaiting preservation: Removing an image from a page (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Removing an image from a page <span class="small">(Page 1 of 1)</span>\

 
Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 07-07-2004 19:58

Hey guys.

Do any of you guys know of a way to remove an image from a page with Javascript?

To add one, I add the tag to document.body.innerHTML; I am wondering if there is a way to remove it without searching innerHTML for a particular substring and cutting it out that way. :/

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

Yossi Admon
Bipolar (III) Inmate

From: Israel
Insane since: Nov 2001

posted posted 07-07-2004 21:55

Hi,
See the following link: http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=25
..."Using element.removeChild(referenceToChildNode), we can remove existing nodes."...

code:
<p id="sample1">Initial text within a paragraph element.</p>

... code to add a text node ...

var text = document.createTextNode(" new text " + (++counter1));
var el = document.getElementById("sample1");
el.appendChild(text);

... code to remove the last child node ...

var el = document.getElementById("sample1");
if (el.hasChildNodes())
el.removeChild(el.lastChild);



(Edited by Yossi Admon on 07-07-2004 22:02)

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 07-07-2004 22:11

innerHTML isn't really the best way to change the contents of an HTML page. You should use the standard DOM instead. I've written a tutorial on this at http://www.slimeland.com/content/articles/jsenhance/ . You can probably skip the earlier parts =)


 

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 07-07-2004 22:22

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 07-07-2004 23:20

Aha, thanks tremendously, all. Works perfectly now. I insert using innerHTML and remove using removeChild, basically since using appendChild makes things messy and complicated.

You can see the WIP at http://www.rpi.edu/~laporj2/media/code/railgun/.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 07-08-2004 03:14
quote:
I tend to disagree: this depends on what you want to achieve exactly.



Well, in browsers where innerHTML is an option, it may be a good option. My statement was based primarily on the fact that - last I knew - innerHTML is not a standard property.


 

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 07-08-2004 08:24

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 07-08-2004 09:30
quote:
I think it has, somehow, become a "standard" property as Opera and Mozilla adopted it.



Just because popular browsers have adopted a feature doesn't mean the feature is safe to use. The more we support unstandard browser features, the more difficult we make it for standard-compliant browsers to enter the browser market. Every web page should work in the theoretical perfectly standard browser. If it doesn't, then you can't predict how it will behave with future versions of current browsers or especially with new browsers.

Admittedly, I'm not so annoyed by the usage of innerHTML as I would be with other things, such as the <font> tag (supported by all popular browsers, but not a good idea to use). Standards are there for a purpose. The reason I'm willing to be a little more lenient with innerHTML is that it *is* very convenient, and it's not unlikely that it would be added to the standard DOM in the future. Nonetheless, the principle is important, so I prefer the usage of standard DOM methods to the usage of unstandard ones.

Every time you use innerHTML, you're giving Microsoft a cookie. =)


 

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 07-08-2004 10:21

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 07-08-2004 10:51

Good points. I strongly agree that innerHTML (or some equivalent) needs to be added to the standard, unless there's a really good argument for why it could cause problems.

For me though, as long as there's a standards-compliant way to do what I want to do, I'll choose that over the nonstandard method.


 

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 07-08-2004 13:42

Count me in, to vote for the standardization of the innerHTML property. I wasn't sure if it was standard or not. A diving of few minutes in the recomandations of the DOM level 1 to 3 gave no infos about the innerHTML property.

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 07-08-2004 15:08

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 07-08-2004 15:54

Ooh, innerHTML isn't standard!? Craziness!

Well, the only browsers I have access to for testing are MSIE, Firefox, Opera, and Safari; and so I wouldn't have known.

For now, however, I think I will go and try to figure out the DOM way to add things... the problem is that it seems entirely confuscated and inelegant. innerHTML is an elegant way to do things, IMHO; and elegance in why I like Javascript.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 07-08-2004 16:28

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 07-08-2004 17:29

It's easier to type document.body.innerHTML+="" than lines upon lines of document.body.appendElement() etc.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 07-08-2004 18:20

My personal opinion/practice is to use the innerHTML element for changing data in a DOM element. Things like text that I want to change, and then use the DOM elements for creating things like divs etc.

The whole standards thing for javascript is a bit wierd since most of the standards are built off of the specific JS implementations as opposed to defining the way the implementations work. A bit of the cart before the horse on those.



.:[ Never resist a perfect moment ]:.

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 07-08-2004 22:43

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 07-08-2004 22:52

The speed and simplicity of low-level always appealed to me; however you pose a valid point. I just wish that they did the DOM methods in a simpler manner; it's difficult to get you're head around, and can be done easier and faster with innerHTML. Less flexible, sure, but I havn't had the need to prune the DOM tree here and there yet (note the keyword yet, heh).

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

« BackwardsOnwards »

Show Forum Drop Down Menu