Dollar sign before var stop working code

Dollar sign before var stop working code
0.0 0

// smooth scroll
  // Add smooth scrolling to all links
  $("a").on('click', function(event) {

    // Make sure this.hash has a value before overriding default behavior
    if (this.hash !== "") {
      // Prevent default anchor click behavior

      // Store hash
      var hash = this.hash;

      // Using jQuery's animate() method to add smooth page scroll
      // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
      $('html, body').animate({
        scrollTop: $(hash).offset().top - 140
      }, 500, function(){

        // Add hash (#) to URL when done scrolling (default click behavior)
        window.location.hash = hash;
    } // End if

Now my question in some cases when setup dollarsign before variable code is not working properly.

Where to need set dollar sign before var names or what is the solution for this?

Like for set numbers there is no dollar sign. But some code stopped working when set it?



The $ is used for jQuery selectors. In your case you assign the string value of this.hash to the variable named hash. Then, when you go to use it in the selector, you can simply write $(hash). For example, if this.hash = “#myHash”, then when you write $(hash), it is as if you wrote $(’#myHash’).