开发者

How do I insert an HTML element in the Google Chrome inspector?

I can double click on attributes and change them in the Google Chrome inspector. 开发者_如何学运维I can add CSS, I can add Javascript to the console. But can I add HTML?


Right-click an element in the inspector, and select "Edit as HTML".

You can then add whatever HTML you want inside of it.


Warning: this will destroy the element with all its descendants, and will then recreate them once you're done editing the HTML. Any event listeners set on any of those elements will no longer work, and any references you might have to any of those elements will be lost.

If you have to keep the elements alive, you'll have to do this programmatically. After selecting the element you want to edit, head over to the console and programmatically add the element you want. Within the console, you can reference the selected element by the variable name $0. For example, if you want to append a div to the currently selected element, type this into the console:

$0.appendChild(document.createElement('div')); 


In Chrome version 100.0.4896 Right-click in the inspector doesn't show the context menu.

So to add HTML element click on the three dots on the left side of the inspector as showing in the below snapshots and select Edit as HTML.

How do I insert an HTML element in the Google Chrome inspector?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜