It is necessary to prohibit the transition on the link at the first click and allow only after the second. Wrote the code:

var clickCount = 0; $(".categoriesPage .categoryBox .textBox").attr("data-count", "0"); $(".categoriesPage .categoryBox .textBox").on("click", function(){ $(this).each(function() { clickCount ++; if (clickCount == 1) { $(this).attr("dataCount", clickCount); return false; } else { return true; } }); 

Does not work, what could be the error? The second option also does not work

 $(".categoriesPage .categoryBox .textBox").attr("data-count", "0"); $(".categoriesPage .categoryBox .textBox").on("click", function(){ $(this).each(function() { var clickCount = $(this).attr("data-count"); clickCount ++; if (clickCount == 1) { $(this).attr("dataCount", clickCount); return false; } else { return true; } }); }); 

    2 answers 2

    Working option:

      $(".categoriesPage .categoryBox .textBox").attr("data-count", "0"); $(".categoriesPage .categoryBox .textBox").on("click", function() { var clickCount = $(this).attr("data-count"); clickCount++; if (clickCount == 1) { $(".categoriesPage .categoryBox .textBox[data-count='1']").attr("data-count", "0"); $(this).attr("data-count", clickCount); return false; } else { return true; } }); 

    And the shortest, thanks to Ivan Belenkov.

     $(".categoriesPage .categoryBox .textBox").one("click", false); 

      The error is that they were going to use the data-count attribute to count the clicks, and in fact use a global variable - one for the whole page.

      And in the code, the dataCount attribute is taken from somewhere dataCount - to which the value is also written, but no one reads it.