Reputation: 63
I want to display a message once the form has been submitted and remove the form from the page.
The first part of the script is working, but the second one (where I try to remove the form) does not.
Any suggestions?
<script>
$(document).ready(function () {
if(window.location.href.indexOf("footer") > -1) {
document.getElementById("thanksForMessage").innerHTML = "<h2>Thanks for the message. I will contact you shortly.</h2>";
var formDiv = document.getElementById("formwell");
var childForm = document.getElementsByTagName("form");
formDiv.removeChild(childForm);
}
});
</script>
Upvotes: 1
Views: 912
Reputation: 50
try to use something like this code
$(document).ready(function () {
if(window.location.href.indexOf("footer") > -1) {
$("#thanksForMessage").html("<h2>Thanks for the message. I will contact you shortly.</h2>");
var formDiv = $("#formwell");
var childForm = "form";
formDiv.remove(childForm);
}
});
Upvotes: 0
Reputation: 33409
var childForm = document.getElementsByTagName("form");
This returns a NodeList (like an array), not a single element. removeChild
expects a single element. You can pass just the first one by:
formDiv.removeChild(childForm[0]);
Upvotes: 2