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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:30:21+00:00 2026-05-28T23:30:21+00:00

I bind an event to a channel on the client side that waits for

  • 0

I bind an event to a channel on the client side that waits for a message from the server and triggers the anonymous function in a callback, passing the message data in the thing parameter.

channel.bind('coordinates_sent', function(thing) {
     var x = thing.left;
     var y = thing.top;

     $(window).scroll(function(){
           alert(x + " " + y);
     });

     alert(x + " " + y);
});

The alert message outside of the scroll method works as expected. It alerts the new x and y coordinates of the data sent from the server right when the new message arrives.

However, the alert message inside the scroll message behaves differently from how I would expect it to. If one message has been sent to the event listener, then the alert correctly displays the x and y coordinates from that message every time I scroll. However, if another message comes in, the alert displays first the original x and y coordinates from the first message, and then a separate alert displays the x and y coordinates from the most recent message.

I’m having trouble understanding why this is happening.

  • 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-05-28T23:30:22+00:00Added an answer on May 28, 2026 at 11:30 pm

    Whenever you’re receiving a message from the server, you’re attaching a new scroll event handler. When you attach an event listener, existing listeners are not removed. When the user scrolls, all attached event handlers are executed.

    To fix this, move the part where it attaches a scroll event outside of the event handler for a message being received by the server:

    var x, y;
    channel.bind('coordinates_sent', function(thing) {
        x = thing.left;
        y = thing.top;
    
        alert(x + " " + y);
    });
    $(window).scroll(function(){
        alert(x + " " + y);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to bind an event to a dynamically created div. function GameField(playerNumber)
I've a table that contains 3 columns. I need to bind an event that
I can bind a jquery event to this element like: <script type=text/javascript> $('#new_key').ready(function() {
This is how to bind multiple events on a couple jQuery selectors: $('#selector1,.selector2').bind('event', function
I'm trying to bind an event to the touchstart, touchmove, and touchend properties that
I bind two event handlers on this link: <a href='#' id='elm'>Show Alert</a> JavaScript: $(function()
I am trying to bind an event to a textbox that contains parameters. The
How can I bind event handler to the custom object that i created? here
I'm considering using live() to bind an event handler to a function I haven't
I have the following jQuery script... $(function() { $('.eventWrapper').bind('click', function(event) { var srvName =

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.