jquery - How to break when contents of a div is changing? -


here code:

<html>    <head>      <script type="text/javascript" src="c:\jquery2.js"></script>      <script type="text/javascript">         $(document).ready(function() {         $('#mydiv').html('hello world');         });      </script>    </head>    <body>       <div id="mydiv">           text...       </div>    </body> </html> 

the scenario is, have no idea changing div content. how use chrome, firefox or firebug (pick one) work out changing 'mydiv'?

ideally want able add break point on div before changes, @ point 'some text...' displayed on screen. step through code , see javascript code interacts div. after stepping through, see div content change 'some text...' 'hello world'. bonkers? please explain why if so.

as want break on dom changes, , not code, can follows:

google chrome devtools:

  1. press f12 call dom inspector.
  2. right-click on element (inside of dom inspector) want break on.
  3. in upcoming context menu choose break on... > subtree modifications

screenshot page:

enabling breaking on subtree modifications in chrome devtools

firebug:

  1. press f12 open firebug.
  2. right-click on element (inside html panel) want break on.
  3. in upcoming context menu choose break on child addition or removal

enabling breaking on subtree modifications in firebug

update

you wish insert data breakpoint prior jquery loading, on page load. can break pointing line of javascript, that not in dom load event, breaks immediately. can insert dom-change breakpoint (in chrome using information above) , continue running. should break on dom change.

<html>    <head>      <script type="text/javascript" src="c:\jquery2.js"></script>      <script type="text/javascript">         alert("breakpoint on line runs during page load");         $(document).ready(function() {             $('#mydiv').html('hello world');  // not run until dom finishes loading         });      </script>    </head>    <body>       <div id="mydiv">           text...       </div>    </body> </html> 

in theory breakpoint on $(document).ready(function() line, debuggers can weird things on lines inline callback


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -