$('.catpics').click(function(){
only binds to links once. You're looking for .on
which will bind to the first object you give it (so you can give it the body
of your webpage) and then tell it to listen for clicks on .catpics
and since the listener is on the body
and not the individual .catpics
elements, it wont matter when the links are actually inserted or deleted:
$('body').on('click', '.catpics', function() {
var id=$(this).attr('id');
$.post('storehouse.php', {catid:id,btn:'showsub'},function(data){
$('#subcatshelf').append('<a class="catpics" id="'+ data+'">'+data+'</a>');
});
});
alternatively you can make click work just fine by pulling out the event handler and just setting up a new clicked listener as you insert a new link:
function clickedCatPic() {
var id=$(this).attr('id');
$.post('storehouse.php', {catid:id,btn:'showsub'},function(data){
var link = $('<a class="catpics" id="'+ data+'">'+data+'</a>');
$('#subcatshelf').append(link);
link.click(clickedCatPic);
});
}
$('.catpics').click(clickedCatPic);