How to get the value of the last child of tag element in JavaScript

1 Answer

0 votes
<!DOCTYPE html> 
<html> 
    <body> 
        <ul id = "ulid"><li>JavaScript</li><li>PHP</li><li>Java</li></ul>
        <script>
            var val = document.getElementById("ulid").lastChild.innerHTML;

            document.write(val);
            
            
            /*
             run:
    
             Java 
            
            */
        </script>
    </body> 
</html>

 



answered Sep 17, 2019 by avibootz

Related questions

...