removeChild on a li inside a ul inside a div with an id?

Posted by Prozaker on Stack Overflow See other posts from Stack Overflow or by Prozaker
Published on 2010-06-14T22:50:58Z Indexed on 2010/06/14 22:52 UTC
Read the original article Hit count: 126

Filed under:
|

I have the following code on a webpage:

<div id="emails">
<ul>
<li>email1</li>
<li>email2</li>
</ul>
</div>

<a href="#" onClick="javascript:deleteEmail">click</a>

and I want to remove the first email, i've been trying with this:

function deleteEmail(){
    var ul = document.getElementById('alt_emails').getElementsByTagName('ul');
    ul.removeChild(ul.childNodes[0]);
}

im kinda new to Javascript DOM, so if there's a better way to do it, please let me know.

Note: I would like to do this without any kind of js framework.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about dom