删除子节点removeChild()

DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>删除子节点removeChild()title>
    
head>
<body>
    <div>
        我是div
        <p>我是pp>
    div>
    <script>
        var div=document.getElementsByTagName("div")[0];//获取父节点div
        var p=document.getElementsByTagName("p")[0];//获取子节点p
        div.removeChild(p);//删除子节点p
    script>
body>
html>

你可能感兴趣的:(删除子节点removeChild())