The following $(this) does not seem to be returning $('.element'). Any ideas why?
$('.element').popover({
container: $(this)
})
The following $(this) does not seem to be returning $('.element'). Any ideas why?
$('.element').popover({
container: $(this)
})
As noted by others, the context of this isn't as you perhaps expected. Perhaps try looping over all the elements.
$('.element').each(function() {
$(this).popover({
container: $(this)
});
});
Inside the scope of the each function, $(this) will refer to a specific $('.element') from the list of all the elements with that class.
In this particular context, this
will refer to whatever happens to be the outer scope. It could be the window
object, or some containing function.
Your code is equivalent to this:
var obj = {container: $(this)}; // <-- this is defined in outer scope
$('.element').popover(obj);