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

  • Home
  • SEARCH
  • 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 8350049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:11:32+00:00 2026-06-09T08:11:32+00:00

I have this following code – <html> <head> <title>Rebound</title> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js></script> <script type=text/javascript> function

  • 0

I have this following code –

 <html>
<head>
<title>Rebound</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">


    function ShowRandom() {
        var $span = $(".random");
        var oldTop = 0;
        var oldLeft = 0;
        var leftPos = 10;
        var topPos = 10;
        var flag = true;

        $(".random").on("click", "#lion", function(event) {
                alert(event.target.id);
            }); 

        $span.fadeOut(500, function() {

            var maxLeft = $(window).width() - $span.width();
            var maxTop = $(window).height() - $span.height();

            oldTop = topPos;
            oldLeft = leftPos;

            leftPos = Math.floor(Math.random() * (maxLeft + 1));
            topPos = Math.floor(Math.random() * (maxTop + 1));          

            $span.css({ left: leftPos, top: topPos }).fadeIn(500);
        });
    };
    ShowRandom();
    setInterval(function(){         
        $('.random').append("<span class='lab'></span>");
        ShowRandom(); 
    }, 1500);
     $('.random').delegate('.lab', 'click', function() {
        $('.random').remove('.lab');
        alert('single event trigger');
    });


</script>
<style>
    span { 
        display: inline-block; 
        position: absolute;
    }
</style>
</head>
<body>
    <div id="container">
        <span class="random"><img src="lion.jpg" width="50px" height="50px" id="lion"></span>

    </div>
</body>
 </html>

I want only one alert box when I click on the image. But I get multiple alert boxes. Is there a way around it?

Thank You

  • 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-09T08:11:33+00:00Added an answer on June 9, 2026 at 8:11 am

    try moving

    $(".random").on("click", "#lion", function(event) {
         alert(event.target.id);
    }); 
    

    outside the ShowRandom function.

    ex:

    function ShowRandom(){...};
    
    $(function(){
    
       $(".random").on("click", "#lion", function(event) {
             alert(event.target.id);
        }); 
    
        ShowRandom();
    
        setInterval(function(){
            $('.random').append("<span class='lab'></span>");
            ShowRandom(); 
        }, 1500);
    
        ...
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this page: http://www.justdoors.co/plinths/bella-matching-plinth.html And the following code to over-ride the css classes:
I have this following code: $(.preview).find(#panel).each(function(i, val) { var x = + $(val).html(); $(x).find(.dmPageHeadline).prepend(
I have this following code and i want to display images and other html
Suppose you have this following code in HTML - <div id=pattern> <span class=a>Content</span> </div>
ok i have this following code that parses JSON from an ajax response using
I have this following code, here CssClass is of the String type. <asp:Panel ID=Panel1
I have this following code which will return all the current semesters. How do
I have this following jquery text fly-in animation.Here is my code before I explain
Never thought I'd have this problem :) The following snippet of code works in
I have the following code: Parallel.ForEach(this.listView2.CheckedItems, new ParallelOptions { MaxDegreeOfParallelism = 4 }, (CheckedItem)

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.