JLThompson999
New Coder
Hello all,
I am trying to make a Chrome extension for a collectible card game that is going to need to involve getting the inner text of all divs with the class "team__monster__level". All of them have have a star special character followed by a number as their inner text. I need the number. But when I try to get the inner text using this code:
I just get "undefined" for each element. I'm pretty sure this is because of the star character, because when I switch the class name to refer to divs that just have text, the code works fine. So how do I just get the number that I need?
I am trying to make a Chrome extension for a collectible card game that is going to need to involve getting the inner text of all divs with the class "team__monster__level". All of them have have a star special character followed by a number as their inner text. I need the number. But when I try to get the inner text using this code:
JavaScript:
function insertScript() {
chrome.tabs.query({active: true, currentWindow: true}, tabs => {
chrome.scripting.executeScript({target: {tabId: tabs[0].id}, function: getData})
})
}
document.getElementById('buttonTwo').addEventListener('click', insertScript)
function getData() {
elements = document.getElementsByClassName('team__monster__level');
allInnerHTML = '';
for (index in elements) {
var element = elements[index];
allInnerHTML = allInnerHTML+" "+element.innerHTML;
};
alert(allInnerHTML);
}
I just get "undefined" for each element. I'm pretty sure this is because of the star character, because when I switch the class name to refer to divs that just have text, the code works fine. So how do I just get the number that I need?