Given the possible slight change in the html markup in the future, how to write the code correctly and extract the category name to which the product belongs from the penultimate li, regardless of the nesting of the product ? In this example, the HTML markup of bread crumbs.
var crumbs = document.getElementById('crumbs'); crumbs = crumbs.lastElementChild; crumbs = crumbs.previousElementSibling; var productCat = crumbs.getElementsByClassName('text-el'); productCat = productCat[0].innerText; console.log(productCat); <p>tetet</p><ul class="items items-crumbs" id="crumbs"> <li class="btn-crumb"> <a href="https://site-name.ru/" typeof="v:Breadcrumb"> <span class="text-el">ΠΠ»Π°Π²Π½Π°Ρ</span> <span class="divider">/</span> </a> </li> <li class="btn-crumb"> <a href="https://site-name.ru/shop/category/konditsionirovanie" typeof="v:Breadcrumb"> <span class="text-el">ΠΠΎΠ½Π΄ΠΈΡΠΈΠΎΠ½ΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅</span> <span class="divider">/</span> </a> </li> <li class="btn-crumb"> <a href="https://site-name.ru/shop/category/konditsionirovanie/nastennye-split-sistemy" typeof="v:Breadcrumb"> <span class="text-el">ΠΠ°ΡΡΠ΅Π½Π½ΡΠ΅ ΡΠΏΠ»ΠΈΡ ΡΠΈΡΡΠ΅ΠΌΡ</span> <span class="divider">/</span> </a> </li> <li class="btn-crumb"> <button typeof="v:Breadcrumb" disabled="disabled"> <span class="text-el">Π‘ΠΏΠ»ΠΈΡ ΡΠΈΡΡΠ΅ΠΌΠ° Mitsubishi Electric MSZ-HJ25VA-ER1/MUZ-HJ25VA-ER1</span> </button> </li> </ul>