Get the created node and update its value : setAttribute « Node Operation « JavaScript DHTML






Get the created node and update its value

 
<head>
<title></title>
</script>
</head>
<body>
<script type = "text/javascript" >

var pTag = document.createElement("p");
pTag.setAttribute("id","myP");
document.body.appendChild(pTag);
pTag.appendChild(document.createTextNode("This is a paragraph."));

var hyperLinkTag = document.createElement("a");
hyperLinkTag.setAttribute("id","myA");
hyperLinkTag.setAttribute("href","http://www.google.com/");
document.body.appendChild(hyperLinkTag);
hyperLinkTag.appendChild(document.createTextNode("Click Here"));

var existingp = document.getElementById("myP");
existingp.firstChild.nodeValue="This is the new text.";
var newanchor = document.getElementById("myA");
newanchor.setAttribute("href","http://www.microsoft.com/");

</script>
</body>

   
  








Related examples in the same category