I have the following:
$('#menu a[href^="/C"], #menu a[href^="/Test"], #menu a[href^="/T"]')
.live('click', function (event) {
.....
.....
});
It looks at each of the menu address links and then adds a function to each. However the function marked by ….. is about twenty lines long and I have up to one hundred address links.
When coded this way does this mean that all of those twenty lines are added to each of the hundred links? Should I change this to use a named function or is that anonymous function created with a system generated name and not stored internally for every link?
You are using event delegation, therefore the event is only bound to the
document. So, no, those twenty lines are only bound in one place.Please use either the
delegatemethod or theonmethod,.liveis depreciated in newer versions of jQuery and is inefficient.or
If you are using a very old version of jQuery and must use
.live, try this syntax instead, it is a little more efficient for your usecase, however must be within a $(document).ready()