Get the text of an li element

Issue

    <ul class="leftbutton" >
            <li id="menu-selected">Sample 1</li>
            <li>Sample 2</li>
            <li>Sample 3</li>
            <li>Sample 4</li>
            <li>Sample 5</li>
    </ul>

I want to get the text of the li item which the id=”menu-selected”.
Right now I am doing something like

   document.getElementById('menu_selected').childNodes.item(0).nodeValue

Is there any simpler way of doing the same?

Solution

In your case:

document.getElementById('menu_selected').innerHTML

Answered By – Alsciende

Answer Checked By – Dawn Plyler (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.