Why the onclick event is triggered after the page is loaded by itself, without pressing?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
7 views
Hello.
Help to understand, have a day without sleep will soon go crazy.
There is a script that hides part of the number

jQuery(document).ready(function($){ $.fn.textToggle = function(cls, str) { return this.each(function(i) { $(this).click(function() { var c = 0, el = $(cls).eq(i), arr = [str,el.text()]; return function() { el.text(arr[c++ % arr.length]); }}()); })}; $(function(){ $('.nomer_shapka').textToggle(".nomer_shapka",").click(); $('.nomer_shapka').textToggle(".num_hide","XX-XX").click(); }); });


A to it HTML code
(999)999-99-99show


The essence of simple code - hiding the last 4 digits of the phone number instead - XX-XX. Clicking on the SHOW button, they appear and the show button disappears. + The goal is sent to Google.

If this objective with the onclick event to hang on any other element of the website all OK, activated at the touch, but in this code the purpose of is triggered itself immediately after page load.

Tell me where I went wrong or what to add to make it work correctly.
by | 7 views

1 Answer

0 like 0 dislike
Your code clicks:

$(function(){
$('.nomer_shapka').textToggle(".nomer_shapka","").click();
$('.nomer_shapka').textToggle(".num_hide","XX-XX").click();
});
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
35,574 users