2

I have input type submit defined inside a form. After some event, I need to replace this button with another button which is already defined hidden in my page. How can I do this in Javascript?

By replace, I mean, say, I have btn1 and btn2. btn1 is inside form1. After an event, btn1 should be replaced with btn2, so after the replacement, btn2 should be part of the form1 and not btn1. And yes, the buttons should do their replacement inside a form tag.

I tried gooogling ofcourse but I can't find the right words maybe?

I need to make it work in IE8.

Note : No JQuery please.

Bnrdo
  • 5,325
  • 3
  • 35
  • 63
  • This may help: http://stackoverflow.com/questions/843680/how-to-replace-dom-element-in-place-using-javascript `btn1.parentNode.replaceChild(btn2,btn1)` – mshsayem Aug 02 '13 at 01:42
  • Please post your code so far. What have you tried other than Googling? – elclanrs Aug 02 '13 at 01:43

1 Answers1

3

Try this:

var firstbtn = document.getElementById("btn1");
var secondbtn = document.getElementById("btn2");
firstbtn.parentNode.replaceChild(secondbtn, firstbtn);
mshsayem
  • 17,557
  • 11
  • 61
  • 69