how to get text from child element from console

I’m trying to get the which is in

as you can see:

<p class="jmbadge">
   <strong>xxx</strong>
   <br>
   <span class="field-value">text!</span>
</p>

I’m trying to get the <span>

this is inside a website and I want to take the text of <span> via the console (Google Chrome)

here is what I tried:

const jminfo = document.getElementsByClassName("jminfo");
const span = jminfo.querySelector('span');
console.log(span);

And here is the error I get:

Uncaught TypeError: jminfo.querySelector is not a function
    at <anonymous>:1:21

Answer

const jminfo = document.getElementsByClassName("jmbadge")[0];

const span = jminfo.querySelector('span');
console.log(span);
<p class="jmbadge">
   <strong>xxx</strong>
   <br>
   <span class="field-value">text!</span>
</p>

Leave a Reply

Your email address will not be published. Required fields are marked *