I have this situation:
<script type="text/javascript">
function myFunction() {
var x = document.getElementById("commentDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
and the php code
<?php
echo "<table><tr onclick='myFunction()'><td>Row A1</td></tr>"; //A1 row from my table
echo "<tr><td><div id='commentDIV' style='display:none'> Row B1</div></td></tr></table>"; // the B1 row show after click on the A1
?>
Everything works fine, when I click on the first row, the second appearance.
How can I use/modify my javascript function in this situation?
<?php
$x=0;
while($x<10){
echo "<table><tr onclick='myFunction()'><td>Row A$x</td></tr>"; //Ax row from my table
echo "<tr><td><div id='commentDIV' style='display:none'> Row B$x</div></td></tr></table>"; // the Bx row must show after click on the Ax
$x++;
}
?>
Please help and save my day! Many thanks!
idmust be unique across the entire DOM (html document). So that affects how you setup a click handler and modify elements.