About the difference between inspecting elements and viewing the source code of a web page

About the difference between inspecting elements and viewing the source code of a web page

I don’t know if you have noticed that when we open any web page with Chrome browser, there are two very similar options when we right-click on the page:

It is to view the source code of the web page and inspect (inspect elements).

I always thought there was no difference between these two options, but since Chrome lists these two options, there must be a reason for it.

Let's take a look at a simple page:


Copy code
The code is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test1</title>
<script>
window.onload = function(){
document.getElementById("p1").innerHTML="This is a sentence generated by JS.";
}
</script>
</head>
<body>
<p id="p1"></p>
</body>
</html>

The display effect on the web page is as follows (most of the blank space is deleted to compress the image size):

We review the elements

You will find that there is an extra sentence in the <p></p> tag.
However, in the source code of the web page, there is no such sentence in the <p></p> tag:

This sentence is dynamically generated by JS.

Therefore, there is a slight difference between inspecting elements and viewing the source code of a web page. This difference can be said to be the difference between source code and DOM. When we inspect elements, we are actually viewing the DOM. After the DOM has been rendered, what we see when we view the source code of the web page is the unparsed source code. The above is the full content of this article. I hope it can be of some help to your study and work.

<<:  HTML+CSS merge table border sample code

>>:  Implementation example of specifying container ip when creating a container in docker

Recommend

CSS sets the box container (div) height to always be 100%

Preface Sometimes you need to keep the height of ...

How to set up FTP server in CentOS7

FTP is mainly used for file transfer, and is gene...

Six ways to reduce the size of Docker images

Since I started working on Vulhub in 2017, I have...

JavaScript to implement login form

This article example shares the specific code of ...

Example code for implementing ellipse trajectory rotation using CSS3

Recently, the following effects need to be achiev...

Understanding JavaScript prototype chain

Table of contents 1. Understanding the Equality R...

MySQL 8.0.3 RC is about to be released. Let’s take a look at the changes

MySQL 8.0.3 is about to be released. Let’s take a...

Linux touch command usage examples

Detailed explanation of linux touch command: 1. C...

How to connect to MySQL visualization tool Navicat

After installing Navicat The following error may ...

Detailed explanation of the pitfalls of Apache domain name configuration

I have never used apache. After I started working...

Detailed explanation of Vue filter implementation and application scenarios

1. Brief Introduction Vue.js allows you to define...

In-depth study of JavaScript array deduplication problem

Table of contents Preface 👀 Start researching 🐱‍🏍...