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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:16:57+00:00 2026-06-07T13:16:57+00:00

I cant seem to figure out how to do this but I am creating

  • 0

I cant seem to figure out how to do this but I am creating buttons that when clicked add a new div to a page containing a textbox. This works fine but what I then want to do is if the user clicks on the div I want the divs id to be popped up in an alert box. The code is below.

HTML

     <table>
     <td>
     <ul id ="firstColumn">
                    <div id="identifier">
                    </div>
                </ul>
            </td>
            <td>
                <ul id ="secondColumn" width="5%">
                    <li><input type="button" class="formCreationButton" id="textAdd"       value="Single line text" /></li>
     </td>
     <ul>
     </table>

The jQuery that adds the div and text box is as follows which works fine.

   $('#textAdd').click(function() {
                var newdiv = document.createElement('div');
                newdiv.innerHTML = "Textbox " + textBoxCounter + " <br><div id='container "+counter+"' class='container'><li><input type='text' value='TEXT' name='textBox " + textBoxCounter +"onclick='display(this)'></li></div></br>";

                document.getElementById("identifier").appendChild(newdiv);
                textBoxCounter++
                counter++;
            });

So everytime I click on the button a new div and text box are created. What I want to do now is when a user clicks on the div an alert box will pop up containing the id of the clicked div. Obviously this is not the only thing I want to do but its the part I am stuck on, below is my attempt.

     $(".container > div").click(function(){
                var divID = this.id;
                alert(divID);
                // do other stuff that needs to be done
            });

The only thing that happens when I click on a div is that an alert pops up saying “content”. I need it to contain something like “container1” or “container2” etc.

Anyway thanks in advance for any help provided, it is greatly appreciated. Pretty new to jQuery so having difficulty with things that may seem simple to others.

  • 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-07T13:16:59+00:00Added an answer on June 7, 2026 at 1:16 pm

    .on API wil do the trick: http://api.jquery.com/on/ demo http://jsfiddle.net/eqDKP/1/

    Please also note that the html table has missing tr tag.

    Hope this helps :)

    code

       $(".container > div").on('click',function(){
                    var divID = this.id;
                    alert(divID);
                    // do other stuff that needs to be done
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys having this really simple problem but cant seem to figure out have
I've looked everywhere for this but I can't seem to figure it out. I'm
This must be quite simple but I can't seem to figure this out. I've
I have read the FactoryGirl documentation, but I can't seem to figure this out.
This is probably really easy but I can't seem to figure out how to
This is probably a simple question but I can't seem to figure out how
This is probably a simple one but I can't seem to figure it out.
This must be simple, but I can't seem to figure it out. I am
I feel very noobish asking this, but I can't seem to figure it out...
This may seem like a silly question but I can't figure it out. let's

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.