Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 658
Flaviu Avatar asked Sep 11 '11 06:09

Flaviu


People also ask

How do I inspect HTML in Chrome?

One of the easiest ways to inspect a specific web element in Chrome is to simply right-click on that particular element and select the Inspect option. Clicking on the Inspect option from the right-click menu will directly open the Developer tools including the editor, Console, Sources, and other tools.

How do I edit HTML inspect in Chrome?

By right-clicking on the HTML in the “Elements” tab and selecting “Edit as HTML,” you can make live edits to the markup of a webpage that Chrome will immediately render once you're done editing.

How do you add a code to inspect?

You can copy by inspect element and target the div you want to copy. Just press ctrl+c and then your div will be copy and paste in your code it will run easily.


1 Answers

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'));  
like image 137
Joseph Silber Avatar answered Oct 02 '22 06:10

Joseph Silber