Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I am trying to make a Chrome extension for an online collectible card game. It will read the card data for the cards used in previous games and conduct a statistical analysis on them to suggest better cards in the future.

As part of this, I need to read the inner text of all div tags with a certain class.

I tried to use getElementsByClassName, as shown, but when I do, nothing happens. Can anyone tell me why?

What I have tried:

function insertScript() {
 chrome.tabs.query({active: true, currentWindow: true}, tabs => {
 chrome.scripting.executeScript({target: {tabId: tabs[0].id}, function: getData})
 })
}
 
// This is an event listener that detects clicks on the battle report button
document.getElementById('buttonTwo').addEventListener('click', insertScript)
 
function getData() {
	alert(document.getElementsByClassName("team__monster__level")[0].innerText);
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900