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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:51:35+00:00 2026-06-01T19:51:35+00:00

I have multiple divs, and I have to write a code like this out

  • 0

I have multiple divs, and I have to write a code like this out for each div, and have php change the id by cycling through $NBR++; at the end. Is there a quicker way to write this once rather than to have this unique for each div?

   // when $NBR = 1
   <div class="playbutton<?php echo $NBR?>">
       <script>
           $(".playbutton<?php echo $NBR?>").click(function()
              {  $(".playbutton<?php echo $NBR?>").hide();
                 $('#songpicture').attr("src", "<?php echo $thumb[$NBR]?>");
              });
       </script>
   </div>


   // when $NBR = 2
   <div class="playbutton<?php echo $NBR?>">
       <script>
           $(".playbutton<?php echo $NBR?>").click(function()
              {  $(".playbutton<?php echo $NBR?>").hide();
                 $('#songpicture').attr("src", "<?php echo $thumb[$NBR]?>");
              });
       </script>
   </div>

This goes on 15 times …etc…..All php variable are set at the beginning of each div with PHP.

So is there a way that I can ‘compress’ this into one code that could be written once? Or must it be written after each div?

Thanks for your help!

  • 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-01T19:51:37+00:00Added an answer on June 1, 2026 at 7:51 pm

    Add this in the top and remove all other script,

     <script>
      $(function () {
         $(".playback_divs").click(function() {  
           $(this).hide();
           $('#songpicture').attr("src", $(this).data('thumb-nbr'));
         });
      }
     </script>
    

    And change your html as,

    <div class="playback_divs playbutton<?php echo $NBR?>" data-thumb-nbr="<?php echo $thumb[$NBR]?>">
    

    Note the html changes

    1) new class playback_divs added to the div.

    2) the data attr data-thumb-nbr.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple divs like this: <div class=small></div> <div class=small></div> <div class=small></div> <div class=small></div>
I have multiple divs, each with a unique id and image. I would like
I have an Html that contains something like: (Multiple divs within div A). <div
I have multiple DIVs containing an image in each. When I rollover these DIVs,
I have multiple text files with logged data like this: 6/23/09 17:00 0.443 6/23/09
I have multiple divs in my body which need the same style: <div class=box></div>
I have have multiple divs' with similar code within it, but also has a
I have multiple divs like setted up below. I want 1 (one) JQuery function
this is kinda tricky to explain,but here goes....I have multiple hidden divs that swap
I have div containing multiple divs and text. The inner divs are alternately floated

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.