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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:09:06+00:00 2026-05-23T04:09:06+00:00

When i embed or use php loops to create multiple div’s with some id.

  • 0

When i embed or use php loops to create multiple div’s with some id.
I want each of them to use with jquery. Say anything like simple hide/show interface.

But as the id is the same it wont work. I assign a variable lets say $i to php loop for the reference of uniqueness. I can assign id to a DOM element with like

           <div id="element-<php echo $i ?>">Bla Bla </div>

Php echoes out here perfectly but how do i use it with jquery something like this:

        $("#element"+<?php echo $i ?>).toggle();

Here it doesnt works.

How do i do it correctly and where am i going wrong ?

Sorry for bad english.

Thanks

  • 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-23T04:09:07+00:00Added an answer on May 23, 2026 at 4:09 am

    the proper syntax for a php code is:

    <?php
    
    //code
    
    ?>
    

    So here you can clearly see what is the error:

    <php echo $i ?>
    

    It should be:

    <?php echo $i; ?>
    

    Updated answer:

    <?php
     for ($k=0;$k<=100;$k++)
      echo '<div id="element-'.$k.'" onclick="toggleID('.$k.')">Here is the content of div $k</div>';
    ?>
    
    <script>
     function toggleID(id)
     {
      $("#element"+id).toggle();
     }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to embed an .asp page on an html page. I cannot use
When you use the WebBrowser control in .NET you can embed an instance of
I'm trying to use the MusiSync font to embed a sharp and flat symbol
I want to embed a wikipedia article into a page but I don't want
I want to embed Javascript in a hobby game engine of mine. Now that
I am trying to embed multiple external websites into one web page. Using an
I have the following javascript to embed a flash in my page.tpl.php <script type=text/javascript>
I know it is common that we use the code below to embed a
We use a video player on our site which gives us the following embed
YouTube allows to use <iframe> to embed videos on sites in addition to flash

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.