Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 706207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:08:25+00:00 2026-05-14T04:08:25+00:00

I have absolutely no idea why this is happening but the following code seems

  • 0

I have absolutely no idea why this is happening but the following code seems to be executed a huge amount 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 its 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');
        }
    });
}); 
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:08:25+00:00Added an answer on May 14, 2026 at 4:08 am

    Basically what you are doing: Every time KeyUp fires, you load the results and attach an additional .click handler to $(‘#save_albums’), which is bad. (jQuery can bind multiple functions to an event, so if you call $(‘something’).click(function(){alert(‘x’);}); 3 times, you get 3 alerts)

    Depending on your exact usage, you can call $(‘#save_albums’).unbind(‘click’); to remove all click handlers before you add it:

                // Unbind existing
                $('#save_albums').unbind('click');
    
                $('#save_albums').click(function(){
                    for(var i = 1; i <= 5; i++){
                        html = $('#your_albums ol li').eq(i).html();
                        alert(html);
                    }
                });
    

    Alternatively, you can try restructuring the source code to have the click handler only attached once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this morning I came across this code, and I have absolutely no idea what
Sorry if this is a dumb question, but I have absolutely no idea how
Right, this is weird, I have no idea why this is happening, but what
I have absolutely no idea how to do this, so I'm just gonna go
So I have this template design that is currently absolutely positioned, but I'm trying
While searching I came across this . It looks interesting but I have absolutely
I have the following python modules. Sorry if the code is ugly. This is
I know that the title is very subtle but I have absolutely no idea
I don't know why this is happening. I have this code here . It
I have absolutely no idea why this is not working. Makes no sense to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.