Clicking on background div only

This is a way to trigger a function when user clicked/touched the background div without hitting it’s child elements.

$('#parentDiv').click(function(e) {
    var clicked = $(e.target);
    if(!clicked.hasClass('parentDivClass')) {
        // do function
    }
});

So the target of the event will be what was clicked. By using a jQuery selector we can do even more fine grain checking (especially useful for very complicated applications) before triggering the function.

 
1
Kudos
 
1
Kudos

Now read this

ES6 Array.prototype.fill

So recently I tried to initialize an array of empty objects in javascript. I wanted it to be configurable with how many elements are present in the initial array as well as what I initialize it with (it may not be an empty object in the... Continue →