how to get data from a span inside a div with javasript [closed]

I have a div with a class and inside it I have a button and a span.

How do I get the data from the span only using JavaScript?

<div _ngcontent-c26 class="ad" fieldname="xzc" panelname="zx">
      
      <span _ngcontent-c26>12345678</span>
      
      <button>hello</button>
</div>

Answer

You can use querySelector to target elements in the DOM with a CSS style syntax – perhaps like:

let div=document.querySelector('div.ad[fieldname="xzc"][panelname="zx"]')