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.

2

1 Answer 1

3

Try this:

var firstbtn = document.getElementById("btn1");
var secondbtn = document.getElementById("btn2");
firstbtn.parentNode.replaceChild(secondbtn, firstbtn);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.