-1

As the Title says, kindly someone explain the use of $ sign in functoin. I am using this code to smooth scroll to ID in WordPress.

When i remove $ sign, code does not work. I have to pass $ in function. kindly refer to image.

Note: This code works without passing $ in function when using in HTML website but does not work in WordPress. Well, that nothing to worry but if some one could explain?

Below is the code:

$(document).ready(function($){
    $('.scroll').on('click',function (e) {
        e.preventDefault();

        var target = this.hash;
        var $target = $(target);

        $('html, body').stop().animate({
            'scrollTop': $target.offset().top
        }, 900, 'swing', function () {
            window.location.hash = target;
        });
    });
});
Danish iqbal
  • 123
  • 1
  • 2
  • 10

1 Answers1

1

The $ is the name of a variable. It is equivalant to jQuery variable. Assume this code:

var $ = "my $ variable";
alert ($);

no magic about it, just a name.

Axel Amthor
  • 10,980
  • 1
  • 25
  • 44