I am using the jQuery function .on()to attach some behavior to an event clickfor an object, for example span.
My setup looks something like this:
$('#container').on('click', 'span', function() {
});
Inside this function thisis span. How do i get it #container?
Full example: http://jsfiddle.net/aymansafadi/Nk3p9/
<div id="container">
<span>Click Me!</span>
</div>β
-
$('#container').on('click', 'span', function() {
var span = $(this),
div = false;
console.log(span);
});β
source
share