-1

I am using $.click() to simulate user interaction with some buttons. The problem is that in addition to simulating the user click, the function scrolls automatically to the element. Is there any way to avoid this?

I made a temporal fix but I don't like it because I have to add two lines and I don't want to add those lines every time I use $.click() in my app. This is what I did:

var current_scroll_position = $(window).scrollTop();
$('.item').click();
$(window).scrollTop(current_scroll_position); 
Alan
  • 2,559
  • 4
  • 32
  • 53

1 Answers1

-2

Check out event delegation with .on() rather than .click(): http://api.jquery.com/on/

Or do something like this:

    $('.item').click(function(e){
      e.preventDefault();
    });

I may be misunderstanding what you're asking for though.

wgallop
  • 157
  • 2
  • 2
  • 11