JavaScript DHTML/Node Operation/setAttribute

Материал из Web эксперт
Перейти к: навигация, поиск

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.ru/");
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.ru/");
</script>
</body>