最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

dom - How to find the snippet of JavaScript that modifies an element? - Stack Overflow

programmeradmin0浏览0评论

The page I'm trying inspect has a hidden <input type="hidden" name="Foo" value="123 /> element on a page, where Javascript/AJAX modifies the value. I'm trying to find where on earth in Javascript is the code that modifies this value from time to time.

Is there a tool that could help me find the places in javascript that use/modify that element? Does Firebug provide this, if so, how?

Note: If tried looking for "Foo" in the code, but I haven't found any matching titles. There's JSON and Mootools loaded, +application specific code, which results several thousands lines of code. The element is probably accessed indirectly.

The page I'm trying inspect has a hidden <input type="hidden" name="Foo" value="123 /> element on a page, where Javascript/AJAX modifies the value. I'm trying to find where on earth in Javascript is the code that modifies this value from time to time.

Is there a tool that could help me find the places in javascript that use/modify that element? Does Firebug provide this, if so, how?

Note: If tried looking for "Foo" in the code, but I haven't found any matching titles. There's JSON and Mootools loaded, +application specific code, which results several thousands lines of code. The element is probably accessed indirectly.

Share Improve this question edited Oct 26, 2009 at 2:20 Christian C. Salvadó 829k184 gold badges928 silver badges844 bronze badges asked Oct 26, 2009 at 2:11 AmericanDadAmericanDad 733 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

Firebug 1.5 will have "Break-on-Modify" on the HTML panel. See http://getfirebug./doc/breakpoints/demo.html#html - Break on DOM (HTML) Mutation Events.

How do you know that the javascript is modifying this value? Since it looks you already know when it's called (since you know it changes), I would suggest a breakpoint in Firebug in the first event that initiates the changing (probably an onclick attribute in other element).

It's kind of hard telling you a "generic" way of knowing where in javascript it's changing Foo's value since there are a lot of different approachs, different libraries, each one with it's syntax.

For example, if you tried searching "Foo" and didn't find it, the script may be traversing the DOM and changing the input's value as a "first child of something". I would try to search for names or ids of input's parent elements and understand the code from there.

I usually just try to understand the javascript logic from every script I use with Firebug's debugging techniques - but just on the script that uses the libraries.

If Firebug doesn't let you define breakpoints on setting some value, you could insert something like this in the page (Firefox-only):

$("textarea")[0].__defineSetter__("value", function(val) {
   alert("called");
})

And either breakpoint on the function in Firebug or use console.log or whatever to dump the stack to the firebug console.

I remember seeing somewhere a presentation on Firebug plans, which included a section on various kinds of breakpoints to be supported, but I can't find a link to it right now.


[edit] The above is for the case the value is set by assigning to the value property: .value = .... If you need to catch the moment an attribute is changed (.setAttribute("value", ...)), you can use DOM mutation listeners.

发布评论

评论列表(0)

  1. 暂无评论