Forum Moderators: open

Message Too Old, No Replies

How to delete elements in a HTML page using Javascript?

Would like to ensure compatibility between different browsers

         

dnimrodx

6:47 pm on Feb 4, 2004 (gmt 0)

10+ Year Member



Hello,

I have a question to ask to those who know how this works properly. How can I delete objects in an DHTML page using javascript and yet ensure compatibility between browsers?

You know, I am not particularly interested on using:


.
:
.
if(document.all)
(if(document.all[elem])!= null)
delete document.all[elem];
.
:
.

Can anyone please help me? I would appreciate it alot!
Thanks in anticipation,

d#Nimrod

DrDoc

6:52 pm on Feb 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Short answer -- you can't.
There is no client side solution that works for all browsers (not even all semi-modern ones).

dnimrodx

6:59 pm on Feb 4, 2004 (gmt 0)

10+ Year Member



What about removing the TAG from the HTML content, Doc?
Wouldn't that work?

DrDoc

7:00 pm on Feb 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, that would work... But not dynamically on the client side. You'd have to use a server side solution (PHP/Perl/ASP) to do that.

dnimrodx

7:12 pm on Feb 4, 2004 (gmt 0)

10+ Year Member



Damnation! I really thought you could remove the actual element's object using Javascript. So I ask: why does it let you create dynamically elements, if you cannot get rid of them?

DrDoc

7:46 pm on Feb 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I really thought you could remove the actual element's object using Javascript.

Ok, let's back up a bit :) In your initial post you said:

How can I delete objects in an DHTML page using javascript and yet ensure compatibility between browsers

The answer to that is that you can't. Yes, you can delete objects (and any element on the page) using JavaScript, but not while maintaining compatibility between browsers. Do you see where I'm getting at, and the difference between the two?

If you're only concerned about actually being able to do it -- great! It can be done using JavaScript. But, don't expect all browsers to behave the exact same way. They all offer different levels of JavaScript support, especially related to more advanced DOM modifications, innerText/innerHTML modifications, nodes, etc.

Plus, to take it one step further -- you will always run into someone who doesn't have JavaScript enabled. Make sure whatever functionality you're trying to create can be done without for those users.

dnimrodx

8:46 pm on Feb 4, 2004 (gmt 0)

10+ Year Member



Ok, let's back up a bit In your initial post you said:

How can I delete objects in an DHTML page using javascript and yet ensure compatibility between browsers

The answer to that is that you can't. Yes, you can delete objects (and any element on the page) using JavaScript, but not while maintaining compatibility between browsers. Do you see where I'm getting at, and the difference between the two?


What I was trying to mean is precisely the same as I first said. I want to be able to delete the object whilst maintaining compatibility between browsers... :)

But thanks Doc for enlighting me. I thought it could be done (although I did not know how).