Home > Article > Web Front-end > How to dynamically create links using js? Tips for dynamically manipulating page elements using js
This article mainly introduces the method of dynamically creating links with javascript, involving the techniques of dynamically operating page elements with javascript. Friends in need can refer to the following
The example of this article describes the method of dynamically creating links with javascript. Share it with everyone for your reference. The specific analysis is as follows:
Example of dynamically creating links:
<html xmlns="http://www.php.cn"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>动态添加链接</title> <script type="text/javascript"> function AppendLink() { var p = document.getElementById("pMain"); var linkTmp = document.createElement("a"); linkTmp.href = "http://www.baidu.com"; linkTmp.innerText = "百度"; //链接要使用innertText,不能使用value p.appendChild(linkTmp); } </script> </head> <body> <p id="pMain"></p> <input type="button" value="添加链接" onclick="AppendLink()" /> </body> </html>
The above is the detailed content of How to dynamically create links using js? Tips for dynamically manipulating page elements using js. For more information, please follow other related articles on the PHP Chinese website!