I'm using jQuery on
function to bind click event:
$('#page-container, .some-class').on('click', '.do-something', function(event) {
// #page-container or .some-class?
});
Now inside callback function I want to know if 'click' event has been fired from #page-container
or .some-class
. With $(this)
I get only selector which has been clicked.
delagateTarget
property of the event
object refers to the target of delegation:
$('#page-container, .some-class').on('click', '.do-something', function(event) {
var dt = event.delegateTarget;
});
http://jsfiddle.net/SmXCG/
try something like this
$('#page-container, .some-class').on('click', '.do-something', function(event) {
$(this).attr('id'); // #page-container
$(this).hasClass('.some-class'); //Will return true if it has some-class
});
You can do something like this:
$('#page-container, .some-class').on('click', '.do-something', function (event) {
if ($(this).closest('#page-container').length)
alert('Its #page-container');
else if ($(this).closest('.some-class').length)
alert('Its .some-class');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With