Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new to Sharepoint. Now i am creating Application Page. My question is, i have a scroll function of 's4-workspace'. My jquery Vesion jquery-1.7.2.min.js

$(document).ready(function () {
         $('#s4-workspace').bind('scroll', function () {
             alert("Called");
         });
})

My unbind code :

$('#s4-workspace').unbind('scroll');

But when i bind the same function it's not woking, Code is

$('#s4-workspace').bind('scroll');

Any suggestion would be helpful.

Thanks.

share|improve this question
1  
$('#s4-workspace').bind('scroll'); you are missing the handler: $('#s4-workspace').bind('scroll',handler); where handler is the function you want to call –  A. Wolff Sep 24 '13 at 13:56
    
@A.Wolff Thanks for reply, please mention the handler, i am a beginner in jquery –  Vasu Shanmugam Sep 24 '13 at 13:58
    
"where handler is the function you want to call"... –  A. Wolff Sep 24 '13 at 14:00

2 Answers 2

up vote 2 down vote accepted

You need to specify the handler every time you bind. Since it looks like you want to bind/unbind multiple times, I would create a named function:

function scrollHandler(e) {
    alert('called');
}

$(document).ready(function () {
    $('#s4-workspace').bind('scroll', scrollHandler);
});

Then later:

$('#s4-workspace').unbind('scroll');

And even later:

$('#s4-workspace').bind('scroll', scrollHandler);
share|improve this answer
    
Thanks For Reply, it's working. But when binding (re-binding), the function scrollHandler is automatically called. is there any way to avoid the scrollHandler function call –  Vasu Shanmugam Sep 24 '13 at 14:14
    
Are you doing .bind('scroll', scrollHandler()); instead of .bind('scroll', scrollHandler); ? –  Jason P Sep 24 '13 at 14:24
    
no my code is $('#s4-workspace').bind('scroll', ScrollHandler); –  Vasu Shanmugam Sep 24 '13 at 14:28
    
Hm, I haven't seen that behavior before. I would guess that a scroll event is being triggered for some reason. Can you reproduce the issue at jsfiddle.net ? –  Jason P Sep 24 '13 at 14:33
    
yes i wrote a code for move to scroll to particular control in page, thats only i am unbind the scroll event before the code called –  Vasu Shanmugam Sep 24 '13 at 14:50

Try this:

 $('#s4-workspace').bind('scroll',function(){
    //code here
 });
share|improve this answer
    
Thanks for reply. i tried your code, but it's not working –  Vasu Shanmugam Sep 24 '13 at 14:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.