How to replace HTML child node with a new node in JavaScript

1 Answer

0 votes
<!DOCTYPE html>
<html>
    <body>
        <ul id="ul_id"><li>PHP</li>
                       <li>JavaScript</li>
                       <li>SQL</li>
                       <li>HTML</li></ul>
        <script>
            var newnode = document.createTextNode("CSS");
            var element = document.getElementById("ul_id").childNodes[0];
            element.replaceChild(newnode, element.childNodes[0]);
        </script>
    </body>
</html>


<!--

CSS
JavaScript
SQL
HTML

-->

 



answered Oct 26, 2019 by avibootz

Related questions

1 answer 134 views
2 answers 246 views
...