How to determine which jQuery event is fired when a text field is clicked?

I have inherited a piece of software and there is a form in it where I cannot figure out where the click event is in jQuery.

When a user clicks a text field on a form, the checkbox next to him switches using a jquery call that I cannot find. I searched for associates.js files and for a living I can not find.

Are there any tools, hints or tricks that I can use to find what is called to trigger the click event so that I can change or deactivate it?

Below is a sample layout around the form:

<li> <input type="checkbox" name="checkbox_other1" id="checkbox_other1" value="checkbox_other1" /> <label for="checkbox_other1">Other <input type="text" id="textfield_other1" name="textfield_other1" size="35" maxlength="35">.</label> </li> <li> <input type="checkbox" name="checkbox_other2" id="checkbox_other2" value="checkbox_other2" /> <label for="checkbox_other2">Other <label for="checkbox_other2"> <input type="text" id="textfield_other2" name="textfield_other2" size="35" maxlength="35">. </label> </li> 

Thanks.

SOLUTION It seems I was thinking too high. It was not jquery / javascript that caused the problem, but it was the tag tags that attached the text box to the checkbox. Thanks for the help.

+4
source share
3 answers

Visual Event is a very convenient tool for finding events on a web page.

You can tag it and then use it on any web page.

Also available as chrome extension .

+3
source

I don’t know why it took me so long to understand, but you can directly print the onclick handler:

 <html> <head> <script> function thisiswhyimhot() { alert("this is why you're not"); } function mybodyisready() { alert(document.getElementById("hottestdivever").onclick); } </script> </head> <body onload="mybodyisready()"> <div id="hottestdivever" onclick="thisiswhyimhot()"></div> </body> </html> 

A warning appears with the following:

 function onclick(event) { thisiswhyimhot() } 

If the handler was installed using jQuery, it is stored in a slightly different way:

 alert(jQuery._data(document.getElementById("hottestdivever"), "events").click[0].handler); 

This will give you something to search in your JS.

And finally, JSFiddle demonstrates vanilla Javascript and jQuery methods.

In other news, I have a new function name for each onload body, from which I write now until the end of time ...

0
source

try event.type

 $("#test").on("click change", function(event){ alert(event.type + " is fired"); }); 
-2
source

Source: https://habr.com/ru/post/1482186/


All Articles