In all of these, we're removing the onclick
from the markup:
You can use a data attribute, like this:
<a class='more' href='#' data-id='<?php echo $showInfo["bID"]; ?>'>mer</a>
Then grab it in your .click()
handler, like this:
$('.more').click(function () {
$('#MoreFriendInfo'+$(this).attr('data-id')).toggle();
});
Alternatively if it's in another container forget the IDs and find it relatively, for example if the markup was like this:
<div class="container">
<a class='more' href="#">mer</a>
<div class="moreFriendInfo">Content</div>
</div>
You could do it like this:
$('.more').click(function () {
$(this).closest('.container').find('.moreFriendInfo').toggle();
});
(In this case you can actually use .siblings()
, but it's meant to be a more general approach)