I have an eventHandler on the entire document, targeting the element with a specific id. That targeted element is a div with some content in it. The eventHandler checks for the 'click'-action. However, whenever I click one of the elements inside the div, it does not activate. Therefore I have to click on the edge of the div for the eventHandler to activate.
Any way to fix this? I was tempted to add an a-element with height/width = 100%, but cannot find a nice way to have it execute a JS function and not just redirect to a link.
Edit 1: here is what's going on:
var inner = createDiv(['page-content', 'small-page-content', 'hover']);
document.addEventListener('click', function (e) {
if (hasId(e.target, index.toString())) {
makeLarge(index);
}
}, false);
function hasId(elem, id) {
return elem.id == id;
}
function createDiv(classes=[]) {
var div = document.createElement('div');
for (var i = 0; i<classes.length; i++) {
div.classList.add(classes[i]);
}
return div;
}
index.toSring() is the id of the div. The div contains: 1 img element, 1 h1 element and 2 sub-divs which each contain a h3 element and an ol. I want the WHOLE div with id index.toString() to be clickable. Right now, only the edges is clickable. Clicking the image etc. does not work.
Edit 2: https://jsfiddle.net/1j3rrtqg/2/ Notice that the text is not clickable, but the edge of the div it (where the div is not covered by another element).
Plain JS please. No jQuery.