Removing a form using JavaScript+DOM

F

francescomoi

Hi.

I've got this HTML page:

------------------------
<HTML>
<HEAD>
<TITLE>Blah</TITLE>
</HEAD>
<form id="foo"><input type="text"></form>
<BODY>
HELLO<br>
</BODY>
</HTML>
 
M

Martin Honnen

<form id="foo"><input type="text"></form>
and I want to remove 'foo' form.

I'm trying with:

In the W3C DOM if you want to remove a node you call removeChild on the
parent node so you need
var formElement = document.getElementById('foo');
if (formElement && formElement.parentNode &&
formElement.parentNode.removeChild) {
formElement.parentNode.removeChild(formElement);
}
 
A

ASM

<form id="foo"><input type="text"></form>
<BODY>

put your form in the body please
and I want to remove 'foo' form.

I'm trying with:

try :
document.body.removeChild(document.getElementById('foo'));
or
document.getElementsByTagName('BODY')[0].removeChild(document.getElementById('foo'));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top