I am attempting to edit some javascript code that is in the html of the page (not an imported js file). I am able to set break points and step through them, but I can not edit the javascript during the execution or before/after execution. I prettified ({}) and un-prettified the files. The code piece is not minified in this section.
- Can I do this?
- Does it matter that the code is inside an attached event. Ie a click etc.
- I am useing jquery obviously.
I could have sworn this used to be a mon feature. But it has been over a year since I have done a lot of javascript.
I am attempting to edit some javascript code that is in the html of the page (not an imported js file). I am able to set break points and step through them, but I can not edit the javascript during the execution or before/after execution. I prettified ({}) and un-prettified the files. The code piece is not minified in this section.
- Can I do this?
- Does it matter that the code is inside an attached event. Ie a click etc.
- I am useing jquery obviously.
I could have sworn this used to be a mon feature. But it has been over a year since I have done a lot of javascript.
Share Improve this question edited Feb 27, 2016 at 20:40 Pavan Teja 3,2021 gold badge17 silver badges22 bronze badges asked Feb 27, 2016 at 19:55 DanDan 8311 gold badge11 silver badges23 bronze badges 5-
Is the
javascript
in existinghtml
page , or only run atconsole
? – guest271314 Commented Feb 27, 2016 at 20:01 - The javascript is in the html of the page. – Dan Commented Feb 27, 2016 at 20:02
- See stackoverflow./questions/18077217/… , – guest271314 Commented Feb 27, 2016 at 20:43
- 1 The problem with that is all of them are creating full "workspaces" and doing a lot more then what I want. I know that I used to be able to make small changes to my javascript and see it work from the dev tools. Is this just not possible any more? do I have to create a full workspace just to do simple changes? – Dan Commented Feb 27, 2016 at 21:01
- 1 It does definitely still work. Try moving your code into a separate JavaScript file. After prettifying you won't be able to edit "script.js:formatted", but you can edit the minified "script.js" file. – Matt Zeunert Commented Feb 27, 2016 at 23:08
1 Answer
Reset to default 5Using chromium / chrome there are several methods to modify the html
of an existing document
. At devtools
Select
Elements
tab, right click on the element to modify, selectEdit as HTML
, make modifications in frame containing element, then click outside of editor frameSelect
Sources
tab, selectSnippets
tab, right click and selectNew
, writejavascript
, to execute in existingwindow
press▶
at right panel to runjavascript
inSnippets
middle panel in existingwindow
. For example if$("body").on("click", function() {alert(123)})
is added as aSnippet
clickingbody
element should callalert(123)
. The event should also be listed inEvent Listeners
at right panel of devtools when inspecting element. Removing the listener may be somewhat more challenging; even if you clickremove
when hovering over the listener at right panel, as the event is already attached to the element. The simplest method would be to add anamespace
to the event$("body").on("click.abcnamespace", handler)
, then call$("body").off("click.abcnamespace")
Modifying text existing handlers will not automatically affect , or cancel the event handler previously attached to the element. The simplest approach would be to copy and save existing
javascript
containing event handler, selectElements
tab , right click on element that has event listener, selectEvent Listeners
at right panel, when hovering over thewindow
,document
orHTMLElement
having event attached a button should be displayed that saysRemove
. Click that button to remove the event listener. You should then be able to modify the saved event listener and add it back to the existingdocument
with modifications being applied