I have a JavaScript function which toggles a div to show/hide, it works if I just have the one link that toggles the single div. But I have a while loop which creates several of these links and div, one for each row. But only the first link works. I can add a $ at end of my id for both the toggle link and div, how do I tell JavaScript to look for this variable?
JavaScript:
$(function(){
var id = document.getElementById();
$('#toggleDiv').click(function(){
$('#targetDiv').toggle();
});
});
PHP:
echo "<a href=\"javascript:void(0);\" id=\"toggleDiv$ctr\">;
echo "<div id=\"targetDiv$ctr\" style=\"display:none;\">";
As you can see, the $ctr helps individualize each link and div, but I need java to identify which #toggleDiv is being clicked, allowing it to toggle the correct #targetDiv.
Any help?