0

I have a below html page

<html>
    <head>
        <title> Test Page </title>

    </head>

    <body>
            <div id="testdiv" style="height:300px; width:200px; overflow:scroll;">
                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div                This is a sample div

                <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
            </div>
            <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
   </body>

</html>

I this page i added the below script

<script>
$( window ).scroll(function(){
    alert('Window Scroll');
});

$('#testdiv').scroll(function(){
    alert('testdiv Scroll');
});

</script>

Which will alert me which scroll action is called.

if i scroll in body it alerts me as Window Scroll

if i scroll in a div which is inside of the body its alerting me as testdiv scroll,Window Scroll

but it should alert only testdiv scroll why its alerting me 2 scroll events

1
  • On my FF 30, i've not this error. Commented Jul 3, 2014 at 13:06

2 Answers 2

3

try this

$('#testdiv').scroll(function(e){
    alert('testdiv Scroll');
    e.stopPropagation();
});
Sign up to request clarification or add additional context in comments.

Comments

2

Your scroll event bubbles up. Please see What is event bubbling and capturing? for the event bubbling explanation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.