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 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 a ASPX Page that contains several user controls, which are loaded dynamically
I have several such anchor links as shown below. <a href=http://google.com onClick=unhook()> Google </a>
I have a page with a div that is dynamically filled using a paginator
My form has several <p> elements which are added dynamically. This is how one
I have a sharepoint site and want to create a script for links with
I have several xml namespaces that expose the same schema. I want to use
I have several classes that I serialize/deserialize, each with a number of properties, some
I have a model that has several properties. The properties can be primitive (String)
I have an unordered list that when an item is clicked it displays several
I have an Access 2003 project in which all data is stored in SQL

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.