How to get the last child node of a specific HTML element in JavaScript

1 Answer

0 votes
<!DOCTYPE html> 
<html>
    <body>
        <ul id="ul_id"><li>JavaScript</li>
                       <li>PHP</li>
                       <li>SQL</li></ul>
        <script>
            var lc = document.getElementById("ul_id").lastChild.innerHTML;
            document.write(lc);
              
            /*
             run:
                
             SQL
      
            */
        </script>
    </body>
</html>

 



answered Oct 25, 2019 by avibootz

Related questions

1 answer 164 views
1 answer 134 views
2 answers 409 views
...