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 8527037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:26:34+00:00 2026-06-11T08:26:34+00:00

The code below takes a div and moves it on click. The return button

  • 0

The code below takes a div and moves it on click. The return button the moves the div back to where it was before. The second alert gets triggered multiples times on occasion. Can someone explain why?

<html>
        <head>
            <script src="js/jquery.js"></script>
            <style>

            .profile {

                width: 250px;
                height: 250px;
                margin-top: 250px;
                margin-left: 250px;
                border: solid black 1px;
            }

        </style>

        </head>
        <body>
        <script>

            $(document).ready(function(){

                $('.profile').click(function(){

                                    // store current position
                    var activeProfile = $(this);
                    var profilePosition = activeProfile.offset();
                    var initialLeft = profilePosition.left;
                    var initialTop = profilePosition.top;


                    alert(initialLeft);

                    $(this).css({'position' : 'absolute', 'top' : 0, 'left' : 0, 'margin': 0});

                            // return to original start position
                        $('#close').click(function(e) {
                        alert('sometimes i get triggered multiple times!');
                        activeProfile.css({'left' : initialLeft, 'top' : initialTop});
                        e.stopPropagation();


                     });    

                });

            })

        </script>

            <div class="profile">
                <button id="close">Return</button>
            </div>

        </body>
    </html>
  • 1 1 Answer
  • 0 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-06-11T08:26:35+00:00Added an answer on June 11, 2026 at 8:26 am

    Looks like the culprit is that every time you click the .profile class it associates a event to #close .. So if you click twice it binds two times.. So you need to unbind and associate again to see the alert only once..

     $(document).ready(function () {
    
        $('.profile').on('click', function () {
    
            // store current position
            var activeProfile = $(this);
            var profilePosition = activeProfile.offset();
            var initialLeft = profilePosition.left;
            var initialTop = profilePosition.top;
    
    
            alert(initialLeft);
    
            $(this).css({
                'position': 'absolute',
                'top': 0,
                'left': 0,
                'margin': 0
            });
    
            // return to original start position
            $('#close').unbind().on('click', function (e) {
                alert('sometimes i get triggered multiple times!');
                activeProfile.css({
                    'left': initialLeft,
                    'top': initialTop
                });
                e.stopPropagation();
    
    
            });
    
        });
    
    })
    

    This is the FIDDLE for old code

    This is the UPDATE FIDDLE with unbind event associated with it..

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

Sidebar

Related Questions

The code below takes an array value, if it's key exist it should echo
the code below works fine but it takes an absolute age to run. How
I have 3 buttons inside div's tages as below. <div id=make_larger> <button type=button>Large</button> </div>
The code pasted below was taken from Javadocs on HttpURLConnection . I get the
I have wrote the code below which was taken from Java How to program
The code below is designed to take a string in and remove any of
In the code below, why it is that when I take the address of
I have a basic PHP question, take the code below for example, let's say
I'm using all of the below to take a field called 'code' from my
Given below is program for encrypting a string. I had taken this code from

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.