i saw this example and trying to understand the theory behind the html if i use class in and id in
why it doesn't work. why i cant remove the child element it gives me error
<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
        <script>
            window.onload = function() {
    var parent = document.getElementsByClassName("demo");
    var child = document.getElementById("p1");
    parent.removeChild(child);
};
        </script>
    </head>
    <body>
        <div class="demo"> 
            <p id="p1">This is a paragraph.</p>
            <p id="p2">This is another paragraph.</p>
        </div>
    </body>
</html>
but if i index parent node it work! i want to know how it work
var parent =document.getElementById("p1");
    parent[0].removeChild(child);
 
     
     
    