javascript's method for dynamically creating links
- 2020-06-15 07:35:49
- OfStack
This article gives an example of how javascript dynamically creates links. Share to everybody for everybody reference. The specific analysis is as follows:
Example of dynamically creating links:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Dynamically add links </title>
<script type="text/javascript">
function AppendLink() {
var div = document.getElementById("divMain");
var linkTmp = document.createElement("a");
linkTmp.href = "http://www.baidu.com";
linkTmp.innerText = " baidu ";
// Links to use innertText, You can't use value
div.appendChild(linkTmp);
}
</script>
</head>
<body>
<div id="divMain"></div>
<input type="button" value=" Add links " onclick="AppendLink()" />
</body>
</html>
I hope this article has been helpful for your javascript programming.