Reputation: 33
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>
Upvotes: 0
Views: 2582
Reputation: 2266
paranula is HTMLElement - kind of JS object, not a string. To access it as a string, use
var parasplit = paranula.outerHTML.split(">");
But if all you need it to take "188" from provided example, use
var result= paranula.innerHTML
The ID of element is other thing - with element like this
<span id="188" class="hiddenid"></span>
you could get "188" with
var result= paranula.id
Upvotes: 2