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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:23:53+00:00 2026-06-10T13:23:53+00:00

In the code below, jquery selector $(:button) is able to select the (+) button.

  • 0

In the code below, jquery selector $(“:button”) is able to select the (+) button.

However, when I create new buttons according to selected value of the dropdown menu. The same selector is not able to select the new (-) buttons.

The code is attached :

 <script>
$(document).ready(function () {
$(":button").click(function () {
        alert("here");
        })
});

</script>

<select id="thing" name="garden" >
<option id="u" selected="selected" ></option>
<option id="1" > Flowers </option>
<option id="2" > Shrubs </option>
<option id="3" > Trees </option>
<option id="4" > Bushes </option>
<option id="5" > Grass</option>
<option id="6" > Dirt</option>

</select>

<button> + </button>

<div id="area"></div>

<button> + </button>
<script>
$("#thing").change(function () {
      var str = "";
      var id="";
      var num=1;
      $("#thing option:selected").each(function () {
            str += $(this).text() + " ";
            id = $(this).attr('id');
    $("#"+id).attr('disabled',"disabled");
          });
      if (id != "u") {
          var tx=$("#area").html();
          var button="<button>-</button>";
          $("#area").html(tx+"<div>"+str+" "+button+"</div>");
      };
    }).trigger('change');
</script>
  • 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-10T13:23:55+00:00Added an answer on June 10, 2026 at 1:23 pm
    $(document).on('click', 'button', function () {
        alert("here");
    });
    

    This is a delegated event handler, which means that it can work on dynamically added elements. From the jQuery documentation for the on method:

    Delegated events have the advantage that they can process events from
    descendant elements that are added to the document at a later time. By
    picking an element that is guaranteed to be present at the time the
    delegated event handler is attached, you can use delegated events to
    avoid the need to frequently attach and remove event handlers. This
    element could be the container element of a view in a
    Model-View-Controller design, for example, or document if the event
    handler wants to monitor all bubbling events in the document. The
    document element is available in the head of the document before
    loading any other HTML, so it is safe to attach events there without
    waiting for the document to be ready.

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

Sidebar

Related Questions

I am using jquery to create a custom dropdown with the code below. I
I'm trying to make a jquery selector as per the below code. However, my
I am new to jquery ! I am using the code below to insert
Below is the code snippet of JQuery code for Chaining vs Callback Function:- $(selector).animate({
Let's say we have the following JavaScript/jQuery code below function createElement(i, value) { return
I am using the code below to create a jQuery UI Dialog widget dynamically:
Below is a jQuery selector that works, and the value is set correctly into
So I wrote the code below: jQuery('#contentWrapper').delegate(.addButton, click, function(){ addRow(jQuery(this)); }); function addRow(thisButton){ var
I have this javascript code below that uses jquery, it is suppoed to be
I am using the below jquery code to call a ajax function in my

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.