#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    100
    Rep Power
    2

    May someone explain this jQuery code to me?


    Code:
    $('a[href=#]').click(function(e) {
    	$(window).scrollTo(0,'slow');
            e.preventDefault();
    });
    Just an FYI: I'm using the scrollTo library of jQuery.
    I understood everything except: passing an argument to the function and what 'e.preventDefault()' is actually doing.
    Thanks, in advance.
  2. #2
  3. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    e.preventDefault();

    is preventing the form from being submitted
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    100
    Rep Power
    2
    Originally Posted by badger_fruit
    e.preventDefault();

    is preventing the form from being submitted
    All right, thanks.

IMN logo majestic logo threadwatch logo seochat tools logo