- ‘target‘ and ‘currentTarget‘ are two most important properties of a java script event.
- ‘target‘is who generated the event and ‘currentTarget‘ is who the invent is intend for.
- These two event properties can be distinguishable from following Example,
— Two ‘UL‘ List is created, The first one with nested ‘LI SPAN‘ sequence and the second one is with only ‘LI‘ element.
— Jquery ‘click‘ event is then attached to ‘LI‘ elements.
— Now If you click on the text of the items of the first ‘UL‘, then you can see below output on your console.As ‘SPAN‘ is nesting around the ‘text‘, it is the target of click and As the event is intended for ‘LI‘ current target is ‘LI‘.
— Now If you click on the text of the items of the second ‘UL‘, then you can see below output on your console. As ‘LI‘ element is nesting around the text, the target and currentTarget both are same ‘LI’ element.
- Check the code below in jsfiddle or try this fiddlelink