Most simple way (assumed you want to remove the element)
<span id='close' onclick='this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode); return false;'>x</span>
Add this inside your div
, an example here.
You may also use something like this
window.onload = function(){
document.getElementById('close').onclick = function(){
this.parentNode.parentNode.parentNode
.removeChild(this.parentNode.parentNode);
return false;
};
};
An Example Here.
Css for close button
#close {
float:right;
display:inline-block;
padding:2px 5px;
background:#ccc;
}
You may add a hover effect like
#close:hover {
float:right;
display:inline-block;
padding:2px 5px;
background:#ccc;
color:#fff;
}
Something like this one.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…