-2

I wonder how to get data from this code. I want to download these numbers, but I don't know how. I have already tried such methods but they did not work.

document.querySelector('.myclass');
document.querySelector('.myclass strong');
document.querySelectorAll('.myclass strong');

And this is the element from which I want to get the numbers. There are two ways on the site but I don't know which will be better so I send 2 items with numbers

<div class="myclass" role="button" tabindex="0">Next number: <strong>97554</strong></div>


or

<div class="anyclass">97532</div>
  • 3
    *"...but they did not work."* Did not work **how**? What did the actual code you used look like? The second one, `document.querySelector('.myclass strong');`, is correct provided you do something with the element once you have it (and provided you want the first matching element). – T.J. Crowder May 07 '20 at 16:04
  • shows null or NodeList [] – ku kubus2 May 07 '20 at 16:39

2 Answers2

0

Did you mean

document.querySelector('.myClass').innerHTML;    
document.querySelector('.myClass').innerText;

Use the data-* attribute to embed custom data. eg:

 <div class='myClass' data-price="123"> Your ticket costs <i> 123 </i> </div>

Then you can use

 document.querySelector('.myClass').getAttribute('data-price');
bosky101
  • 2,066
  • 1
  • 16
  • 10
  • unfortunately there is no access to change it because it is on the page and I can't edit it. I needed a way to download this item without change – ku kubus2 May 07 '20 at 16:27
0

You need to use .innerText to get the numbers in the strong tag

document.querySelector('.myClass strong').innerText;
jmona789
  • 2,350
  • 4
  • 19
  • 44