Home  >  Article  >  Web Front-end  >  How to change the original content of html through js

How to change the original content of html through js

不言
不言Original
2018-06-12 14:33:081983browse

The following will bring you a method to implement js to change the original content of html. The content is quite good, so I will share it with you now and give it as a reference.

is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js改变html的内容</title>
<!-- 不能把JavaScript写在这个头部来改变html的内容-->
</head>

<body>
<!-- 不能把JavaScript写在定义pid的前面来改变html的内容-->
<p id="pid">Hello Html!</p>
<script type="text/javascript">
	document.getElementById("pid").innerHTML="绝地反击";//js改变html的内容
</script>
</body>
</html>

The above is The entire content of this article is hoped to be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to use DOM in JS to control HTML elements

How to use js to splice html strings

The above is the detailed content of How to change the original content of html through js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn