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

  • SEARCH
  • Home
  • 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 3594594
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:44:06+00:00 2026-05-18T19:44:06+00:00

I am currently using jquery function(below) to display a block on click of a

  • 0

I am currently using jquery function(below) to display a block on click of a text.
can’t i generalize it $(‘#totalcomments’+id).click or something , In below code no is a integer. basically i have a set of repeating div’s whose format is hiddencomments1, hiddencomments2 ……… So on click on a text whose id=totalcomments1 i want to display the div whose id=hiddencomments1

function showcomments(no)
{
 $('#totalcomments'+no).hide();
 $('#hiddencomments'+no).show();
}
  • 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-05-18T19:44:07+00:00Added an answer on May 18, 2026 at 7:44 pm

    Looks like I’ve joined the show a little late, but you should really, really, really consider using delegate or liveto bind your events instead of click.

    If, as you said in a comment, you could have up to 9,999 elements to bind this event for, with click you’re getting each one and binding the same event to each of them; not good. With live or delegate however, you bind the event once to an shared-ancestor of the elements (document in the case of live), and take advantage of JavaScript’s event bubbling mechanism. This is infinitely more efficient.

    As mentioned by @lonesomeday in the comments, the difference between live and delegate is the syntax you use to first bind the event; live selects the elements to begin with, where-as delegate doesn’t.

    (delegate > live > click)

    Whether it’s a id-starts-with or class approach you choose, the notion is still the same:

    $(document).delegate('[id^=totalcomments]', 'click', function() {
        $(this).hide();
        $('#hiddencomments'+this.id.replace('total','hidden')).show();
    });
    

    or

    $('.yourSharedClass').live('click', function() {
        $(this).hide();
        $('#hiddencomments'+ this.id.replace('total','hidden')).show();
    });
    

    Again, looking at this from a performance point of view, using a class based system would be quicker.

    I’ve done one example using live and another with delegate, to provide an example of using both.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below you'll see a javascript/jQuery function I'm currently using: var forward = new RegExp('forward'),
I am currently using jQuery .click() method to update 15 text fields with simple
I'm using the JQuery AJAX function to deliver data to a PHP doc. Currently,
I'm currently doing a highlighting function on a webpage and im using the jquery
Currently I'm using Netbeans to create a webpage. The code is listed below, and
I'm currently using jQuery to make a div clickable and in this div I
I'm currently using JQuery to assign colors to containers. In Chrome and IE, when
I'm currently using jQuery Cookies plugin, and depending on which side of the page
I am currently using jQuery to load a variable php layout depending on the
I am currently using jquery corner for making a div round cornered. But the

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.