If I add an anonymous jQuery function to many elements, does it repeat many times?

I have the following:

$('#menu a[href^="/C"], #menu a[href^="/Test"], #menu a[href^="/T"]')
        .live('click', function (event) {
.....
.....
        });

He looks at each of the links to the menu address, and then adds each function. However, the function marked with ..... is about twenty lines, and I have up to a hundred address links.

When coding this way, does this mean that all of these twenty lines are added to each of hundreds of links? Do I have to change this to use a named function or is it an anonymous function created with a system generated name and not stored inside each link?

+3
source share
1 answer

, document. , , .

, delegate on, .live jQuery .

$("#menu").delegate('a[href^="/C"], a[href^="/Test"], a[href^="/T"]','click',function(){...});

$("#menu").on('click','a[href^="/C"], a[href^="/Test"], a[href^="/T"]',function(){...});

jQuery .live, , usecase, $().ready()

$('a[href^="/C"], a[href^="/Test"], a[href^="/T"]','#menu').live('click',function(){...});
+4

All Articles