var elem = $('#'+ id)[0]; var children = elem.children[0].children; var duration = children[1].innerText; Gives an error message:
Cannot read property 'children' of undefined
(on the 2nd line). But if I try to bring the children variable to the console, I will get back not undefined , but what I need is the descendants of the elem element. If I try to output children[1].innerText , I get what I need. Why then do i get an error? If you display console.log(children.toString()); , then [object HTMLCollection] is displayed. Here is the html code (which is dynamically loaded):
<div class="song local" id="pc-9" url="some path"> <ul> <li class="name">Bob Dylan - Blowin' in the wind</li> <li class="duration">2:49</li> </ul> </div>
children" - contradict each other. If an error occurs in the 2nd line, thechildrenvariable will not be assigned. Try to reformulate the question. Markup html will also be useful. - Igor