I dont know why .each() not working here in my code
function showhide(id){
$('#mydiv'+id).each(function(){
if(this).is(":visible") ) {
$(this).css('display','none');
}else {
$(this).css('display','block');
}
});
}
<span id="mydiv" style="display:none;">
blah blah blah
</span>
<a href="#" onclick="showhide($id);return false;" />show/hide</a>
You are using an id selector – id’s should be unique within the page, so calling .each with an id selector makes no sense.
Instead assign a class to each of the elements involved and use