< ;script type="text/javascript"> function test(){ //createElement() Create an element with a specified tag name [for example: dynamically create a hyperlink] var createa=document. createElement("a"); createa.id="a1"; createa.innerText="Connect to Baidu"; createa.href="http://www.baidu.com"; //createa.color="green" ////Add color (don't forget the style attribute, otherwise it will have no effect) createa.style.color="green" //Add default location-- body and add child nodes //document.body.appendChild(createa); //Place the specified position > function test2(){ //Delete node at specified position removeChild() document.getElementById("div1").removeChild(document.getElementById("a1")); //Duplicate id name js only takes the first }
< input type="button" value="Create an a tag" onclick="test()"/>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn