Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

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:

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?
 
Back
Top Bottom