Home  >  Article  >  Web Front-end  >  JS function modifies the element content of html and how to modify the attribute content

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

高洛峰
高洛峰Original
2016-12-08 14:47:081677browse

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>

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>



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