$('a[href^="#"]').click(function() { // Код return false; }); 

I read in the documentation that you can convert to:

 $('a[href^="#"]').on('click', function() { // Код return false; }); 

handler is the function to be installed as a handler. Instead of a function, you can specify the value false, it will be equivalent to setting such a function: function () {return false;}.

 $('a[href^="#"]').on('click', function(false) { // Код }); $('a[href^="#"]').on('click', false) { // Код }); 

But something is not what is not, I do not understand how, or simply do not correctly prescribe?

  • one
    What is your task? I can not catch the meaning of installing an event handler that will always return false . - XelaNimed
  • @XelaNimed The meaning of the obvious - disable the work of intra - page links - tutankhamun

1 answer 1

Carefully look in the browser console, for sure the errors fall out. The jQuery documentation provides an example:

 $( "a.disabled" ).on( "click", false ); 

You have written too much

 $ ('a [href ^ = "#"]'). on ('click', false)   {
    // Code
 })   ;
  • That is, if instead of a function I specify false, then inside the function I can’t write any code with? - Rodion Polyakov
  • one
    @ RodionPolyakov Of course. The purpose of this abbreviation is not to write a function. In the jQuery source, this replaces an empty function with returning false . If you need a code, write a function that returns false after executing the code - tutankhamun