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 990025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:53:04+00:00 2026-05-16T05:53:04+00:00

I have several dynamically created links and forms on one page named with IDs

  • 0

I have several dynamically created links and forms on one page named with IDs sub_comment_form_[id] and sub_add_comment_[id], respectively. I’m trying to:

  1. Hide all forms when the page loads
  2. Bind a click event to the link directly above the form to hide/show the form.

I’m not sure if there is a problem with my selectors, or if jQuery simply does not allow binding on multiple objects at once. Here is my code:

HTML

<a href="#" id="sub_add_comment_to_answer_[id]">Add comment</a>
<form id="sub_comment_form_to_answer_[id]"...

jQuery

$("form[ @id^='sub_comment_form' ]").hide();

$("a[ @id^='sub_add_comment' ]").click(function() {
  var sibform = $(this).next("form");

  if (sibform.is(':hidden')) {
    $(this).text('Cancel');
    sibform.slideDown('fast');
  } else {
    $(this).text('Add comment');
    sibform.slideUp('fast');
  }
});
  • 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-16T05:53:05+00:00Added an answer on May 16, 2026 at 5:53 am

    If you’re using a newer version of jQuery (1.3+) there’s no @ on attribute selectors anymore, it just looks like this:

    $("form[id^='sub_comment_form']").hide();
    //and..
    $("a[id^='sub_add_comment']").click(function() {
    

    This first one was also missing a closing brace, so be sure to fix that too 🙂

    Also, be sure both of these are wrapped in a document.ready handler so they execute after the DOM is ready, like this:

    $(function() {
      $("form[id^='sub_comment_form']").hide();
      $("a[id^='sub_add_comment']").click(function() { ... });
    });
    

    Alternatively, instead of these ID starts-with selectors you could use a class, for instance:

    <a href="#" class="addComment">Add comment</a>
    

    And bind it like this:

      $("a.addComment").click(function() { ... });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several buttons on my app that are being created dynamically. They are
I have a page with several dynamically generated DropDownLists. The DDs load and display
I have a ASPX Page that contains several user controls, which are loaded dynamically
I have several log files of events (one event per line). The logs can
I have web layout, which can contains several links on it. Those links are
I have a dynamically created table which in the last <td> there is a
I have created several Q about correctly mapping a website with a database so
Im trying to create a user control menu where links to a page's usercontrols
I have several DropDownLists on a form which are dynamically populated as they move
I have several classes, that all derives from SuperClass. When the classes are created,

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.