You can use the innerText
property for most browsers, but the textContent
property for Firefox:
<ul>
<li id="myLi">Hello, world</li>
</ul>
var li = document.getElementById("myLi")
console.log(li.textContent || li.innerText);
Here is a fiddle to demonstrate.
If you are using jQuery (you say you are, but I see no evidence) it would be as simple as using the .text() function:
$("#myLi").text();
If your <li>
contains HTML markup too, you may want that. In this case you need to use the innerHTML
property:
document.getElementById("myLi").innerHTML;
Again, jQuery has it's own equivalent .html() which caters for all sorts of different browsers:
$("#myLi").html();
<li>
element you want to get the text for? Does it have a specific ID? Does it have a unique class with a specific<ul>
? Showing some of your HTML might help clear this up – Subbase