I have changed my coding style with more complex projects to loading pages (And their embedded scripts) “on demand” recently. However, it is difficult to debug those scripts as when they are loaded like:
jQuery.get('/myModularPage', function(html){ /* insert the loaded page into the DOM */ });
or
$('#some-container').load('/myOtherPage');
These scripts run perfectly, but if I’m debugging, how can I set breakpoints in these dynamically loaded pages and scripts?
UPDATE
The accepted form is now with a
#(hashtag) rather than@(at symbol)The syntax was changed to to avoid conflicts with IE conditional compilation statements and some other issues (thanks to Oleksandr Pshenychnyy and Varunkumar Nagarajan for pointing this out)
This can really be any string that helps you identify the block of code.
An additional good point from JMac:
ORIGINAL
I struggled with the above for about a week before running across this article. It really does work perfectly for my development environment (Chrome 22 as I write this).
For example, given this simple html document:
Things I haven’t yet discovered: