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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:03:50+00:00 2026-05-19T15:03:50+00:00

I have an HTML div : <div id=’text_icon_<?php $i++; ?>’ class=text_icon>Some Text</div> that I

  • 0

I have an HTML div:

<div id='text_icon_<?php $i++; ?>' class="text_icon">Some Text</div>

that I print inside a foreach loop. I am using ajax to handle the click() event on it and change its text to Done!, so I have an output like:

<div class="text">Done!</div>

If I run the loop 4 times and I click on one of the divs (i.e. the one with class text_icon) then only first one is working while the rest of the divs are not working.

  • 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-19T15:03:50+00:00Added an answer on May 19, 2026 at 3:03 pm

    Update:

    Your update indicates the below is not the problem, the IDs are unique.

    Without your jQuery code it’s hard to help you debug, so here’s an example of how it can be done:

    HTML:

    <div id='text_icon1' class='text_icon'>Div #1</div>
    <div id='text_icon2' class='text_icon'>Div #2</div>
    <div id='text_icon3' class='text_icon'>Div #3</div>
    <div id='text_icon4' class='text_icon'>Div #4</div>
    

    JavaScript code using jQuery:

    $("div.text_icon").click(function() {
    
      // Within the `click` handler, `this` points to the
      // DOM element. If you're kicking off some ajax something,
      // you'll probably be doing something like this:
    
      // Grab `this` to a variable we can access from the
      // `success` closure
      var theDiv = this;
    
      // Do our call
      $.ajax({
        url: "your_url_here",
        success: function() {
          // It worked, udate the div
          $(theDiv).text("Done!");
        }
      });
    
    });
    

    Live copy


    Original answer:

    If you’re really using “DIV id=’text_icon’ class=”text_icon…./DIV”, e.g.:

    <DIV id='text_icon' class="text_icon">....</DIV>
    

    …then the problem is that the id is not unique. ID values must be unique on the page (reference). That would seem to fit with the symptom you describe, with “only the first one” working. Most browsers, when given invalid HTML with multiple IDs, will use the ID on the first element in document order and ignore the remaining ones.

    If you don’t need the div to have an ID at all, you can just remove it. Otherwise, just ensure the ID is unique, e.g.:

    <DIV id='text_icon1' class="text_icon">....</DIV>
    <DIV id='text_icon2' class="text_icon">....</DIV>
    <DIV id='text_icon3' class="text_icon">....</DIV>
    <DIV id='text_icon4' class="text_icon">....</DIV>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have html code block like this <div id=some-div> <a href=# class=link-click>some link text</a>
I have html like so: <div class=foo> (<a href=forum.example.com>forum</a>) <p> Some html here.... </div>
I have this html: <div class=foo parent> <div class=child></div> </div> with some css: .foo{
I have html that looks like this, <div> <span>Text <a href=example.html>ABC</a> <a href=example.html>DEF</a> <a
I have HTML that looks like this: <body class=style_0> <div> <div class=style_1>Pending Test List</div>
If I have html forms like: <form> <div class=searchbox><input type=text name=searchbox id=searchbox></div> <div class=searchbtn><input
I have this html div tag defined: <div style=height:100px; width:100px class=total-title> first text </div>
I have some HTML DIV elements that contain a narrative style of form. For
I have HTML that looks like this: <div class=item-list> <h3>Monday Sep 21</h3> <h3>Tuesday Sep
I have html code that looks roughly like this: <div id=id1> <div id=id2> <p>some

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.