After generating divs using php for loop and also dynamically assigning for them ids how to i target the ids using jquery?

Am using a while loop to out various elements each containing rows from a mysql database. I was able to make each div have different id however, i have no idea how i can target each of the divs usings jquery through the ids so that each div is a clickable link.
Here is a part of my code

 <!-- php script -->
 <?php
   require_once 'controllers/fetchVids.php';

   if (mysqli_num_rows($result) > 0) {
       // output data of each row
       while($row = mysqli_fetch_assoc($result)) {
           $fileName = $row[$filePath];
           $file = basename($fileName);
           $mb = round($row[$size] / (1000000), 2);

           echo "
                <div class='container search-output' id=''>
                    <div class='row song-info' id='file-$row[$videoId]'>
                        <div class= 'col col-sm-6 artist'>
                            $file
                        </div>
                    <div class= 'col col-sm-3 song-title'>
                        <span>Size:</span>
                        $mb mb
                    </div>
                    <div class= 'col col-sm-3 song-title'>
                       <span>Downloads:</span>
                       $row[$downloads]
                    </div>
             </div>

                <div class='row-lower'>
                   <a href='#' class='icon all-links'>
                       <i class='fa fa-whatsapp'></i> Share
                   </a>
                       <i class='fa fa-clock duration'></i> Duration $row[$duration] mins
               </div>
                               
              </div> 
             ";
       } else {
            echo "No New Videos";
            }

        mysqli_close($connection);
       ?>

Someone please show me the right jquery to do the above. thank you
Below is the jquery code i tried but it rather opens all the divs and not only that that a user clicks on

$(document).on('click', '.song-info', function() {
  // alert(this.id);
  if (this.id) {
    window.location = "./song-details.php";
  }
});

55 thoughts on “After generating divs using php for loop and also dynamically assigning for them ids how to i target the ids using jquery?”

  1. After generating divs using php for loop and also dynamically assigning for them ids how to i target the ids using jquery? – JavaScript Help amoxicillin [url=https://amoxilotc.com]amoxicillin clavulanate[/url] amoxicillin 200 mg for dogs

    Reply

Leave a Comment