i guess you wanted something like this ?
you can also use fontAwesome in the after
element or a background-image.
header {
height:100px;
width:100px;
position:relative;
background:Red;
}
header:after {
content:"X";
position:absolute;
right:0;
top:0;
color:#fff;
transition:0.3s ease-out;
opacity:0;
}
header:hover:after {
opacity:1;
}
<header contenteditable="true" id="title" onkeyup="store(this.id);"></header>
option2. using plain Javascript
added the fontAwesome icon using javascript ( beforeend
= inserted right before the end of the header
tag -> you can use beforebegin,afterbegin,beforeend,afterend
see more here insertAdjacentHTML )
then, you can add a click event on the previously added icon. ( here i am toggling the class of header changing it's color )
let me know if it helps
var newElem = document.getElementById("title");
newElem.insertAdjacentHTML('beforeend', '<i id="clickme" class="fa fa-times-circle" aria-hidden="true"> </i>');
document.getElementById("clickme").onclick = function() {
newElem.classList.toggle('blue');
};
header {
height: 100px;
width: 100px;
position: relative;
background: Red;
transition: 0.3s;
}
header:hover .fa {
opacity: 1;
}
.fa {
color: white;
position: absolute;
top: 0;
right: 0;
cursor: pointer;
opacity: 0;
}
header.blue {
background: blue;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<header contenteditable="true" id="title" onkeyup="store(this.id);"></header>