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="">
<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 = "";
  linkTmp.innerText = " baidu "; 
  // Links to use innertText, You can't use value
 <div id="divMain"></div>
 <input type="button" value=" Add links " onclick="AppendLink()" />

I hope this article has been helpful for your javascript programming.

Related articles: