I am trying to search my html for class ardiv and then search this class for span.
Then i want to get value from this span element using split function, but i am getting this error:
Uncaught TypeError: paranula.split is not a function
function hledat() {
var divs = document.getElementsByClassName("ardiv");
for (var i = 0; i < divs.length; i++) {
var para = divs[i].getElementsByTagName("span");
var paranula = para[0];
console.log(paranula);
var parasplit = paranula.split(">");
console.log(parasplit[1]);
}
}
hledat();
<span class="hiddenid">188</span>
splitfunction and notparanula.id?splitis for splitting strings not selecting/filtering elements or fetching attributes.0th element returned bygetElementByTagNameis not the span you are expecting. Try narrowing down on the selector; maybe anidwould be a better approach.IDwas confusing. Instead of parsing the span HTML as a string, just useparseInt( paranula.innerText )and that will get the id as a number.console.log(document.querySelector('.ardiv .hiddenid').textContent);