How to remove next element using JavaScript (without using jQuery)

aman picture aman · Jun 27, 2013 · Viewed 9.2k times · Source

I need something like this.

<a onclick="SaveNote(this);" >Save</a>
<a href="javascript:void(0);" id="112">Cancel</a>
<a href="javascript:void(0);" id="112">Delete</a>

If I click on the Save anchor , I want to remove all three anchor elements as shown above, without using any id, and replace them with an Edit anchor. I currently have some Javascript code that looks something like this :

function SaveNote(e){
   e.nextSibling.removeNode;
   e.nextSibling.removeNode;
   e.nextSibling.removeNode;
}

Have you any idea regarding this issue?

Answer

user405398 picture user405398 · Jun 27, 2013

removeNode seems to be non standard. Try this:

if(e && e.nextSibling) {
  e.parentNode.removeChild(e.nextSibling)
}