Home > Web Front-end > JS Tutorial > body text

JS function modifies the element content of html and how to modify the attribute content

高洛峰
Release: 2016-12-08 14:47:08
Original
1671 people have browsed it

Modify element content:

<body>
<p id="pid">Hello</p>
<button onclick="demo()">按钮</button>
<script>
function demo(){
var nv = document.getElementById("pid");
nv.innerHTML="World";
}
</script>
</body>
Copy after login

Modify element label attributes:

<body>
<a href="http://www.baidu.com/" id="aid" >呵呵</a>
<button onclick="demo()">按钮</button>
<script>
function demo(){
document.getElementById("aid").href="http://www.jikexueyuan.com";
}
</script>
</body>
Copy after login



Related labels:
js
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template