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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:49:12+00:00 2026-05-31T09:49:12+00:00

I want to assign a function to several div (show + i) at the

  • 0

I want to assign a function to several div (“show” + i) at the same time, each call will assign another div (“theDiv” + i), but the “+i” does not work.

$("#show"+i).click(function()
{
$("#theDiv"+i).show("normal");
});

If I remplace the “i” by its values(0,1,2…) the code is working. So why can I correct this?
this is the entire function:

function getInfoProduits1()
{

    var request = new XMLHttpRequest();
    if(i<idProduits.length)
        {
            request.open("GET","http://patisserie-orient.fr/prestashop/prestashop/api/products/"+idProduits[i]+"?PHP_AUTH_USER="+PHP_AUTH_USER+"&ws_key="+ws_key,true);

            request.onreadystatechange = function()
                {
                    if(request.readyState==4)
                    {
                        //alert("Status2 is  "+request.status);
                        if (request.status == 200 || request.status == 0)
                        {
                            response1  = request.responseXML.documentElement;
                            nameProduits[i] = response1.getElementsByTagName('name')[0].getElementsByTagName('language')[0].firstChild.data;
                            //alert(nameProduits[i]);
                            priceProduits[i] = response1.getElementsByTagName('price')[0].firstChild.data+" €";
                            //alert(priceProduits[i]);
                            descriptionProduits[i] = response1.getElementsByTagName('description_short')[0].getElementsByTagName('language')[0].firstChild.data;
                            //alert(descriptionProduits[i]);
                            quantitieProduitsDisponible[i] = response1.getElementsByTagName('quantity')[0].firstChild.data;
                            //alert(quantitieProduitsDisponible[i]);

                            maDiv = document.createElement("div");
                            maDiv.id = 'id_de_la_div'+i;

                            malabel = document.createElement("div");
                            malabel1 = document.createElement("div");
                            mon_bouton1 = document.createElement("button");
                             maDiv2 = document.createElement("div");
                            mon_bouton1.id="show"+i;
                            maDiv2.id="theDiv"+i;
                            maDiv2.innerHTML="Détails:";
                            maDiv2.style.display="none";
                           //mon_bouton1.value='click';

                           $("#show"+i).click(function(){

            $("#theDiv"+i).show("normal");
            });
                         mon_bouton1.onclick='aff();';
                            malabel.innerHTML=nameProduits[i];
                            malabel1.innerHTML=priceProduits[i];
                            maDiv.innerHTML='<img src="Images/Icones/dollars.png" width="50" height="50" align="right">';
                            //maDiv.innerHTML='<button type="button" id="show" onclick="aff();">Détails</button> ';
                            maDiv.className="ui-bar ui-bar-e cadre";
                            document.getElementById("divbar").appendChild(maDiv);
                            document.getElementById('id_de_la_div'+i).appendChild(malabel);
                            document.getElementById('id_de_la_div'+i).appendChild(malabel1);
                            document.getElementById('id_de_la_div'+i).appendChild(mon_bouton1);
                            document.getElementById('id_de_la_div'+i).appendChild(maDiv2);
                            maDivvide = document.createElement("div");
                            maDivvide.innerHTML='<br>';
                            document.getElementById("divbar").appendChild(maDivvide);
                            i++;
                             getInfoProduits1();
                         }
                     }
                }

            request.send();

        }   
    else
        {
            return;
        }

}
  • 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-31T09:49:13+00:00Added an answer on May 31, 2026 at 9:49 am

    I don’t understand what you really mean but maybe this is what you need

    //attach an event handler to all elements with an id that starts with "show"
    $("[id^=show]").click(function(){
       //get only the number from the clicked id
       var i = this.id.replace("show", "");
      //show the relevant div
      $("#theDiv"+i).show("normal");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create threads and assign different function for each thread using c#?
I want to know How JQuery assign function name to $ ?
What I want to do is following. Inside a function, I need to assign
I want to assign categories based upon the format of the book that will
I feel like a bonehead: I want to assign index=i to each LI I
Say I have a .mat file with several instances of the same structure, each
I have a function that returns a number. I want to assign a variable
I want to assign a value to each letter in the alphabet, so that
I have an iframe on my page. I want to assign a function to
I want to do something like: class Name{ function assign($name,$value){ } } Which is

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.