原型应用, HTMLElement ,给所有HTML元素都添加一个新方法


DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Documenttitle>
head>
<body>

    
        <div id="a">aaaaaadiv>
        <div id="b">bbbbbbdiv>

    
    




    <script type="text/javascript">

        HTMLElement.prototype.remove = function(){
            if (this.parentNode){
                this.parentNode.removeChild(this);
            };
        };

        
            var a = document.getElementById("a");
            a.parentNode.removeChild(a);

            // 
            document.getElementById("b").remove();
    script>
body>
html>