user3874356 user3874356 - 6 months ago 8
jQuery Question

Fetch html content of child tag inside li

I have a list like:

<ol id="id1">
<li><strong>aaa</strong><em>bbb<br />ccc</em></li>
<li><strong>111</strong><em>222<br />333</em></li>
</ol>


How do I get the html content of
<em>
tag within each
<li>
?

I tried using jQuery's
.html()
method but is behaving inconsistently on android html5 app I'm trying to make. Android 5.1 above are able to read that well, but android 4.4.2 device doesn't doesn't display anything.

Is there an alternate way of getting html please?

Thanks!

Answer
var liElements = document.getElementById("id1").getElementsByTagName("li");
for(var i=0;i<liElements.length;i++){
    alert(liElements[i].getElementsByTagName("em")[0].innerHTML);
}