You need to pass event object to function to get the item that triggered the event, event.target will give you the source element.
Live Demo
$('#p').bind('click', function(event) {
alert(event.target.id);
});
or
Live Demo
$('#p').bind('click', function(event) {
alert($(event.target).attr('id'));
});
Edit
The first method event.target.id
is preferred over second $(event.target).attr('id')
for performance, simplicity and readability.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…