Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7979303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:44:33+00:00 2026-06-04T09:44:33+00:00

I have the following: $(‘#menu a[href^=/C], #menu a[href^=/Test], #menu a[href^=/T]’) .live(‘click’, function (event) {

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:44:34+00:00Added an answer on June 4, 2026 at 9:44 am

    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 delegate method or the on method, .live is depreciated in newer versions of jQuery and is inefficient.

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

    or

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

    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()

    $('a[href^="/C"], a[href^="/Test"], a[href^="/T"]','#menu').live('click',function(){...});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following HTML menu: <ul> <li><a href=index.html>Index Page</a></li> <li><a href=#some-page>Some Page</a></li> </ul> Let
I have following databases: test table1 fields: id, password, name, lastname test2 table2 fields:
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
I have following link in a.aspx file: <a href=a.htm target=iframe>A</a> I want to set
I have following problem: My program should decide at runtime to load an function
I have following query in my project, $values = array(test=>value) $this->_db->update(tablename,$values,array('id = ?'=> $data['id'],'wid
Have following kernel function: private static String programSource = __kernel void sampleKernel(__global float *Y,
I have following relation. A company has several employees. Each employee is defined by
I have following image map code. <area shape=rect coords=213,109,320,256 href=embedded-processors alt=Embedded Processor class=embeded-processor />

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.