How do I make the below function more dynamic for example commentLink and commentContainer will have an ID after them like this commentLink-2289 commentContainer-2289 because there will be multiple ones in a list.
Javascript
$(function() {
$("#commentLink").click(function()
{
$("#commentContainer").toggle();
if ($("#commentContainer").is(":visible"))
{
$("#commentContainer").load($(this).attr("href"));
} else
{
$("#commentContainer").html("Loading..."); //Or just leave it as is...
}
return false; //Prevent default action
});
});
Html
<div id="SystemNews">
<ul id="dc_news">
<li>
<a href="/Home/SystemNews/69" id="commentLink-0">Comments</a>
<div id='commentContainer-0' style="display:none;"> Loading...</div>
</div>
</li>
</ul>
</div>
Note: Please provide a working example, I learn best by example thanks