Click event keeps firing
- by Ben Shelock
I have absolutely no idea why this is happening but the following code seems to be executed a huge ammount of times in all browsers.
$('#save_albums').click(function(){
    for(var i = 1; i <= 5; i++){
        html = $('#your_albums ol li').eq(i).html();
        alert(html);
    }
});
Looks fairly innocent to me...
Here's the code in it's entirety
$(function(){
    $('#query').keyup(function(){
        var text = encodeURI($(this).val());
        if(text.length > 3){                        
            $('#results').load('search.php?album='+text, function(){
                $('.album').hover(function(){
                    $(this).css('outline', '1px solid black')
                },function(){
                    $(this).css('outline', 'none')
                });
                $('.album').click(function(){
                    $('#fores').remove();
                    $('#yours').show();                                 
                    if($('#your_albums ol li').length <= 4){
                        albumInfo = '<li><div class="album">' + $(this).html() + '</div></li>';
                        if($('#your_albums ol li').length >= 1){
                            $('#your_albums ol li').last().after(albumInfo);
                        }
                        else{
                            $('#your_albums ol').html(albumInfo);
                        }
                    }
                    else{
                        alert('No more than 5 please');
                    }
                });
                $('#clear_albums').click(function(e){
                    e.preventDefault;
                    $('#your_albums ol li').remove();
                });
                $('#save_albums').click(function(){
                    for(var i = 1; i <= 5; i++){
                        html = $('#your_albums ol li').eq(i).html();
                        alert(html);
                    }
                });
            });
        }
        else{
            $('#results').text('Query must be more than 3 characters');
        }
    });
});