5

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

When the user clicks in a textbox on the form, the checkbox next to it toggles using a jquery call that I cannot seem to find. I've searched the associates .js files and for the life of me I cannot find it.

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

Below is a sample of the markup 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 So it seems I was thinking too high level. It wasn't jquery/javascript that was causing the issue, but it was the label tags that was attaching the textfield to the checkbox. Thanks for all the assistance.

15
  • Couldn't you provide link to your website? Commented May 22, 2013 at 14:41
  • Seems you're having another person's code. Programmatically there is no way to find out which other method triggered your second input's click event. Your best bet probably is to use text search for .click() or .trigger('click') eventually substituting the single quote with a double quote. Commented May 22, 2013 at 14:46
  • Sorry, can't provide a link. It's on a dev server that can't be accessed without credentials. Commented May 22, 2013 at 14:53
  • I searched for click and toggle, and neither has shown a suitable piece of code that could be responsible. Commented May 22, 2013 at 14:53
  • 1
    Try using some other online tools that help pinpoint these things, for example Visual Event. Commented May 22, 2013 at 16:28

3 Answers 3

4

Visual Event is very handy tool to find events on webpage.

You can bookmark it and then use on any webpage.

Also available as chrome extension.

Sign up to request clarification or add additional context in comments.

Comments

0

Don't know why this took me so long to realize, but you can print the onclick handler directly:

<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> 

Will Pop up an alert with the following:

function onclick(event) { thisiswhyimhot() } 

If the handler was set with JQuery it's stored in a slightly different fashion:

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

That will give you something to search for in your JS.

And finally, a JSFiddle demoing both the vanilla Javascript and jQuery methods.

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

Comments

-2

try event.type

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

5 Comments

I don't think OP is looking for that
-1: You just read the title and ignored the question, didn't you?
Thanks. I know how to trigger an event, but I can't seem to figure out which/where the event is being fired.
try event.target. In jQuery event.target always refers to the element that triggered the event.
I know the element that triggered the event, I'm trying to find the handler that is causing the checkboxes to toggle.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.