2021-04-28

Loop through ul li elements and get the li text excluding childrens

Hello how can i loop through ul li elements and get the text content only from the li, excepting the text content of its children?

<li class="lom">@paul<div class="on-off">offline</div></li>

I want to get only the @paul without offline, I have tried this:

var lnx = $('.cht(ul class) .lom');
for (let i = 0; i < lnx.length; i++) {
    var txt = lnx[i].textContent;
    console.log(txt + '\n');
}

But i get @pauloffline



from Recent Questions - Stack Overflow https://ift.tt/3dXfOAG
https://ift.tt/eA8V8J

No comments:

Post a Comment