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 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 that looks roughly like this: <div id=id1> <div id=id2> <p>some
I have some HTML and jQuery that slides a div up and down to
I have this html div tag defined: <div style=height:100px; width:100px class=total-title> first text </div>
I have HTML code similar to <div class=menu> <div>Latest</div> <div>Oldest</div> </div> I loop through
If I have a HTML form with some embedded div s, and after the
I have an html like this: <div id=container1> <div class=dragme>drag me</div> </div> <div id=container2>
So I have some html like so: <div id=avatar_choices> <label for=id_choice_0> <input id=id_choice_0 type=radio
I have the following html <div id=menu> <ul class=horizMenu> <li id=active><a href=# id=current>About</a></li> <li><a
I have a basic HTML form that gets inserted into a server side div
I have HTML like this: <div> <div class=a> content1 </div> content 2 <div class=a>

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.