Home > Article > Web Front-end > JS function modifies the element content of html and how to modify the attribute content
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>