I want to add a overlay on the images of a website when you hover them. I implemented this here and it's working fine http://jsfiddle.net/stujLbjh/
This is the js code:
var divs = document.querySelectorAll('.image-thumb');
for (var i = 0; i < divs.length; i++)
{
var overlay = document.createElement('a')
overlay.className = 'icon-overlay';
overlay.href = '#';
divs[i].appendChild(overlay);
divs[i].onmouseover = function () {
this.querySelector('.icon-overlay').style.display = 'block';}
divs[i].onmouseout = function () {
this.querySelector('.icon-overlay').style.display = 'none';}
overlay.onclick = function() {
alert("clicked");}
}
Further on, i wanted to get rid of those div declarations in html that are including the imgs and add them dynamically straight from javascript, in order to have the same result as in the first jsfiddle, but the behaviour is weird and i miss something. You can see that here: http://jsfiddle.net/uwrae91p/1/
Any hints?
Zack.