In JavaScript, I am making a contact form, and I have tried to make an exit button, which on click, deletes the contact form. However, it doesn't work:
var box = document.createElement('div');
box.id='contactForm';
var title = document.createElement('div');
title.id='formTitle';
title.innerHTML = "Contact Us";
var i = document.createElement('img');
i.src = 'images/exitBtn.jpg';
i.id = 'exitButton';
i.addEventListener('click', function(){var b = document.getElementById('contactForm'); b.parentNode.removeChild(b);});
I tried this too:
i.addEventListener('click', function(e){var b = document.getElementById('contactForm'); b.parentNode.removeChild(b);});
What should I do?
Edit - Included all the code:
CSS
#contactForm
{
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
height: 650px;
width: 525px;
background-color: #CCC;
margin: auto;
z-index:9999;
color:white;
box-shadow: 1px 1px 1px 1px #444;
}
.contactText
{
padding-top: 5px;
padding-bottom: 5px;
outline: none;
padding-left: 20px;
width: 480px;
height: 31px;
border: 1px solid #666;
background-color: #777;
font-family: "Iceland";
color: #FFF;
font-size: 1.2em;
-moz-transition: all 0.35s ease-in-out;
-webkit-transition: all 0.35s ease-in-out;
-o-transition: all 0.35s ease-in-out;
-ms-transition: all 0.35s ease-in-out;
transition: all 0.35s ease-in-out;
}
.contactTextArea
{
padding-top: 10px;
padding-bottom: 10px;
outline: none;
padding-left: 20px;
width: 478px;
resize: none;
height: 125px;
border: 1px solid #666;
background-color: #777;
font-family: "Iceland";
color: #FFF;
font-size: 1.2em;
-moz-transition: all 0.35s ease-in-out;
-webkit-transition: all 0.35s ease-in-out;
-o-transition: all 0.35s ease-in-out;
-ms-transition: all 0.35s ease-in-out;
transition: all 0.35s ease-in-out;
}
#contactHolder
{
margin: auto;
position: relative;
width: 502px;
height: 615px;
}
.contactText:hover,
.contactTextArea:hover
{
background-color: #888;
-moz-transition: all 0.35s ease-in-out;
-webkit-transition: all 0.35s ease-in-out;
-o-transition: all 0.35s ease-in-out;
-ms-transition: all 0.35s ease-in-out;
transition: all 0.35s ease-in-out;
}
#exitButton
{
padding-top: 5px;
padding-bottom: 5px;
padding-right: 5px;
float: right;
}
#exitButton:hover
{
cursor: pointer;
}
#contactSend
{
padding-top: 9.5px;
padding-bottom: 9.5px;
height: 35px;
background-color: #888;
width: 125px;
float: right;
font-family: "Iceland";
color: #FFF;
font-size: 1.2em;
}
.contactText:focus,
.contactTextArea:focus
{
background-color: #999;
-moz-transition: all 0.35s ease-in-out;
-webkit-transition: all 0.35s ease-in-out;
-o-transition: all 0.35s ease-in-out;
-ms-transition: all 0.35s ease-in-out;
transition: all 0.35s ease-in-out;
}
#formTitle
{
text-align: center;
width: 525px;
height: 35px;
font-family: "Iceland";
font-size: 2.5em;
background-color: #EEEEEE;
color: #000;
}
JavaScript
var w = document.getElementById("wrapper");
w.style.opacity = 0.4;
w.style.filter = 'alpha(opacity="40");';
var box = document.createElement('div');
box.id='contactForm';
document.body.appendChild(box);
var title = document.createElement('div');
title.id='formTitle';
title.innerHTML = "Contact Us";
var i = document.createElement('img');
i.src = 'images/exitBtn.jpg';
i.id = 'exitButton';
i.addEventListener('click', function(){var b = document.getElementById('contactForm'); b.parentNode.removeChild(b);});
title.appendChild(i);
box.appendChild(title);
box.innerHTML += '<br>';
var h = document.createElement('div');
h.id='contactHolder';
box.appendChild(h);
var name = document.createElement('input');
name.placeholder = 'Name';
name.className = 'contactText';
h.appendChild(name);
h.innerHTML += '<p></p>';
var mail = document.createElement('input');
mail.placeholder = 'E-Mail Address';
mail.className = 'contactText';
h.appendChild(mail);
h.innerHTML += '<p></p>';
var message = document.createElement('textarea');
message.placeholder = 'Message';
message.className = 'contactTextArea';
h.appendChild(message);
h.innerHTML += '<p></p>';
var send = document.createElement('div');
send.id = 'contactSend';
send.innerHTML = 'Send Message';
h.appendChild(send);
ebut you don't use it? That's not different than the other version