// Event handling with jQuery
//
// Step 1
//
// Set up event handler(s) for div.item elements so that:
// on mouseover, the "hover" class is added AND the img "src" attributed is logged to the console
// on mouseout, the "hover" class is removed
// on click, the div is hidden (hint: hide())
var clickHandler = function(e) {
$(this).hide();
}
var moHandler = function(e) {
$(this).removeClass("hover");
};
var handler1 = function(e) {
// this === the element handling the event (a DOM node)
$(this).addClass('hover');
e.target; // the source, not necessarily the same
console.log($(this).find('img').attr('src'));
};
$("div.wrapper")
.on('mouseover', "div.item", handler1)
.on('mouseout', 'div.item', moHandler)
.on('click', 'div.item', clickHandler);
// Step 2
//
// All done? Did you delegate?
// If not, set it up so that you are delgating
// event handling to the wrapper div
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.