Lynda.com has a great series of tutorials on JavaScript, here. One of the exercises was an event bubbling demo, written in JavaScript. It illustrates how events on a DOM element, bubble-up to the parent elements. I have re-written it below in JQuery.
Click in ‘div 3′ to see the event propogate.
function getEventTarget(e) { if (window.event != null) return window.event.srcElement; else return e.target; } function doEventb(e) { var target = getEventTarget(e); alert("body target:" + target.getAttribute('id') + " type: " + e.type); } function doEvent1(e) { var target = getEventTarget(e); alert("div1 target: " + target.getAttribute('id') + " type: " + e.type); } function doEvent2(e) { var target = getEventTarget(e); alert("div2 target: " + target.getAttribute('id') + " type: " + e.type); } function doEvent3(e) { var target = getEventTarget(e); alert("div3 target: " + target.getAttribute('id') + " type: " + e.type); } $(function () { $("body").bind("click",doEventb); $("#div1").bind("click", doEvent1); $("#div2").bind("click", doEvent2); $("#div3").bind("click", doEvent3); });
Another Layout Demo
Clicking on a random word will fire an event and color one of the little boxes.
The main concept here is that javascript can load different layers of an image, where there is a background layer, and then layers with a lot of transparency and only a small content change. This layout is pretty terrible, but I hope to use the technique in a more finished project at some point.