I have some buttons and content made dynamically from my database. I need to be able to press a button and have it toggle the content in the associated <pre>.
I am able to get jQuery to have click events with each button, but it only shows the content of the most recently created <pre>.
I just don't know how to get each button to interact with the correlating <pre> tag. Any help would be appreciated.
echo "<div class='my-buttons'>";
for ($j = 0; $j < $num; ++$j)
{
  $row = $result->fetch_array(MYSQLI_ASSOC);
  echo "<button id=title>".$row['title']."</button>";
  $code = base64_decode($row['code']);
  echo "<pre style='display:none' id='code'>$code</pre>";        
}
echo "</div>
$('.my-buttons').on('click', (e) => $('#code').slideToggle('slow')))
 
     
    