Remove element

  • Thread starter Pos yo, quién si no!
  • Start date
P

Pos yo, quién si no!

Hi Ng,

I created a div dynamically with the following code:

var d = document.createElement("DIV");
d.setAttribute("id","test");
document.body.appendChild(d);

I don't know how remove it (for example, clicking
it with the mouse).

Thanks in advance,

Vaka
 
I

Ivo

I created a div dynamically with the following code:

var d = document.createElement("DIV");
d.setAttribute("id","test");
document.body.appendChild(d);

I don't know how remove it (for example, clicking
it with the mouse).

To remove an element, use the removeChild() method of its parent element,
like so:

var d = document.getElementById( 'test' );
d.parentNode.removeChild( d );

BTW, very important: please set your newsreader to send plain-text only to
newsgroups.

hth
ivo
http://4umi.com/
 
P

Pos yo, quién si no!

Hi Ivo,
To remove an element, use the removeChild() method of its parent element,
like so:

var d = document.getElementById( 'test' );
d.parentNode.removeChild( d );

Works great!

BTW, very important: please set your newsreader to send plain-text only to
newsgroups.

I hope this msg are correct!

Thanks, ;-)

Vaka
 

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

Staff online

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top