I've been trying, unsuccessfully, to close/remove a DOM element when an image is clicked. I have built the code for the elements to be called onload but now I need for them to close or be removed from the body onclick of an image.
This is the code to call the element:
function myFunction() {
var embed = document.createElement('embed');
embed.setAttribute("src", "http://www.domain.com");
embed.setAttribute("width", "100%");
embed.setAttribute("height", "100%");
var content = document.createElement('div');
content.id = 'content';
content.className = 'content_layer';
var close = document.createElement('div');
close.id = 'close';
close.className = 'close_layer';
var close_link = document.createElement('a');
close_link.setAttribute("href", "javascript:NEED CODE HERE????");
var close_img = document.createElement('img');
close_img.setAttribute("src", "http://img.com");
close_img.setAttribute("width", "100%");
close_img.setAttribute("height", "100%");
content.appendChild(embed);
close.appendChild(content);
close_link.appendChild(close_img);
close.appendChild(close_link);
document.getElementsByTagName('body')[0].appendChild(close);
}
window.onload = myFunction();
Specifically, I need for the "close_link" to remove the "close" element from the body. Since all other elements are a child to this, I'm assuming they will all close as well once the "close" is removed (please correct me if i'm wrong here).
Any suggestions using Javascript? Also, please note I'm not looking to add jquery to this...
Thanks!
Jon