Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removechild alternatives 1

Status
Not open for further replies.

j4606

MIS
Nov 28, 2005
349
US
Hi,
I have a element which is dynamically created and sometimes i need to remove it. The element is appended to differnt divs based on user interaction.

Right now Im doing something like, and it works but it seems rather silly.
Code:
document.getElementById("someDiv").parentNode.removeChild(document.getElementById("someDiv"));

I want something like.

Code:
document.getElementById("someid").destroy! RAWR!

You know what i mean. I know I could prototype something but does anyone know another way?
 
Sadly, you can't even make a prototype for it. Remove child is the "correct" way to do it. Unless there's another way to do it that I don't know about, you can't assign methods to HTML objects in IE. Run this in FF and IE, it'll work in FF but IE will have no part in it:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

Object.prototype.destroyRAWR = function () {
   this.parentNode.removeChild(this);
}

window.setTimeout("document.getElementById('blah').destroyRAWR()", 2000);


</script>

<style type="text/css">

</style>
</head>
<body>

<div id="blah">tizzest!</div>

</body>
</html>


-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B> bites again.[/small]
 
Good point, thanks for the reply. I just started working with prototype and jquery(building the same app in two differnt libaries to see which one we are gonna use for some of our dev) and they have some nice functionality. For example in jquery I would do something like $(element).remove(), I think. Sometimes I would like to use these libraries as they make development so much easier. But then again I don't want to include a bunch of js files cause I'm too lazy to write a few lines code. Maybe soon browsers will offer better built in methods so the need to extesion libraries are reduced. For example firefox 3 will have getElementsByClassName! score!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top