If you're trying to use .on()
so that you can listen to events on DOM object that may be created after you make the initial .on()
call, then the most efficient way to do so is to find an existing parent object that won't come and go and you can bind event listeners to now.
.live()
put all listeners on the document object (the master parent) and could get pretty inefficient if you had a lot of listeners.
.on()
allows you to specify what that parent object will most efficiently be. So, if you want to put all these event handlers in one statement and these '#header .fixed-feedback-bn, #sb-sec .feedback-bn' don't have a common parent, then you'd have to specify document as that parent like Greg has written.
But, a more efficient way of doing this would be to break this apart according to need. For the elements that have no dynamic need, just bind directly to that element. For example if #header and #sb-sec doesn't come/go and doesn't need dynamic behavior, you can just find directly to it like this:
$('#header, #sb-sec').on('click', function() {
// code here
});
And, for elements that you need some dynamic behavior, pick an appropriate common parent and hook onto that like this using the common parent as the catch point for the events and the selector as the filter for which sub-elements you want the event to fire for:
$('#feedback').on('click', '.feedback-bn, .fixed-feedback-bn', function() {
// code here
});
.on()
or.click()
is the most efficient. I made an assumption that if they neededlive()
it was because they didn't want to lose their listeners, but perhaps that was not a correct assumption. – Arsenical