0

I have just started using querySelector. I want to get the text data of first non empty element without concerning the element name (p or div or span).

For example: 1)

<div>
  <span></span>
  <span>data</span>
  <span>data1</span>
<div>

2)

<div>
  <ul>
    <li></li>
    <li>data</li>
  </ul>
  <span>data1</span>
<div>

In both the cases I want to get the text data of first element that is non empty. In 1 case from the second span and in 2 case from the second li. Is that possible?

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
  • Possible duplicate of [getElementsByTagName() equivalent for textNodes](http://stackoverflow.com/questions/2579666/getelementsbytagname-equivalent-for-textnodes) – James Donnelly Apr 25 '17 at 12:02
  • I've marked this as a duplicate because the answers to that question can be used to grab all text nodes, then you'd simply pull only the first one. – James Donnelly Apr 25 '17 at 12:03

0 Answers0