473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Removing a element (DOM/JS)

Ok I am one of those unfortunate souls who have to make a text editor for
CMS.

So, I need to remove a <textarea> on a page (this is for non javascript
browsers).

I can figure out the element (getLelementById), but so far have been unable
to remove it. I tried to set the elements innerHTML to "". Interestingly,
in firefox the element is doubled (1.0.4).

anyone have any help with this. I have ie support to work on too, so *any*
pointers for *any* browsers on replacing elements with javascript are very
very welcome.

Jul 23 '05 #1
4 12407

Jam Pa wrote:
So, I need to remove a <textarea> on a page (this is for non javascript
browsers).

I can figure out the element (getLelementById), but so far have been unable
to remove it.


if (element.parentNode && element.parentNode.removeChild) {
element.parentNode.removeChild(element);
}

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Martin Honnen <ma*******@yahoo.de> wrote in
news:42***********************@newsread2.arcor-online.net:

Jam Pa wrote:
So, I need to remove a <textarea> on a page (this is for non
javascript browsers).

I can figure out the element (getLelementById), but so far have been
unable to remove it.


if (element.parentNode && element.parentNode.removeChild) {
element.parentNode.removeChild(element);
}


Thanks for your reply.

The code below works.. at times. And sometimes it wont. Go figure...

<div id="supa">
<p>ldakjsdlkjaslkjsad</p>
<p>etc</p>
<textarea id="tarea"></textarea>
<script language="JavaScript" type="text/javascript">
function removeElementById() {
parn = "supa";
rele = "storyarea";
pare = document.getElementById(parn);
rele = document.getElementById(rele);
fstatus = "";

if (tarea.parentNode && tarea.parentNode.removeChild
(tarea)) { tarea.parentNode.removeChild(tarea); }
else { alert("Nada!"); }
fstatus = "jaa";
return fstatus;
}
removeElementById();
</script>
</div>
Jul 23 '05 #3
Ok well this is how Im working this script in 'final' (lol):

function removeElementById(remele) {
remele = document.getElementById(remele);
if (remele.parentNode && remele.parentNode.removeChild(remele)) {
remele.parentNode.removeChild(remele); }
}

removeElementById("storyarea");

I hope this may help someone out there
Jul 23 '05 #4
Jam Pa wrote:
Ok well this is how Im working this script in 'final' (lol):
Please don't post code with tabs, replace them with spaces. It nearly
always
causes wrapping that introduces errors.

function removeElementById(remele) {
remele = document.getElementById(remele);
if (remele.parentNode && remele.parentNode.removeChild(remele)) {
Here you will actually call the removeChild method, not just test it.
The intention is to test the method, and if it's supported, call it:

if ( remele.parentNode && remele.parentNode.removeChild ) {
remele.parentNode.removeChild(remele); }
}

If the method is not supported, you will get an error from the if(..),
if the method is supported, you will get an error from this line
because 'remele' was already removed in the test.

removeElementById("storyarea");

I hope this may help someone out there


I hope this helps you! 8-p

--
Rob

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim Ley | last post by:
Hi, IE has the ability to setExpressions on stylesheets so you can calculate the value of the css property through script. For various reasons I'm wanting to use a side-effect of this to...
1
by: Stanimir Stamenkov | last post by:
I've wondered if it is right thing to do: element.parentNode.insertBefore(element, beforeElement); where 'beforeElement' is one of the 'element.parentNode.childNodes'? First, I've used: ...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
9
by: AA | last post by:
Hello, I need to extract an element from a xml document something like this <myXml> <Header> <Name/> <LastName/> <Age/> </Head> <Body> <Properties>
3
by: Chantal | last post by:
Hello everybody, I'm relatively new to javascript + DOM so I've a question : I'm removing <div> elements in DOM with javascript. It works perfectly in Firefox and Opera : I mean the DOM is...
7
by: Simon Hart | last post by:
Hi, I have a requirement to remove the xmlns from the DOM in order to pass over to MS CRM 3.0 Fetch method.It seems the fetch method blows up if there is a xmlns present!?! The reason I have a...
2
by: MedIt | last post by:
Hi, I am new in using xsl.I am stuck in a simple task,which is trying to remove an atribute from a node,and keep the rest of the attributes of this element in the xslt. I have tried a couple of...
6
by: bgold12 | last post by:
Hey, I just want to make sure that when I remove an element I don't have to worry about the events listeners I added previously to the element. For example: // get the element by its id elem =...
0
by: Alien | last post by:
I came across this problem where I cant remove element from the document. Here is my code. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder builder =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.