Is there any way to get the text data of first non empty element using query selector

房东的猫 提交于 2020-01-25 21:43:02

问题


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?

来源:https://stackoverflow.com/questions/43607844/is-there-any-way-to-get-the-text-data-of-first-non-empty-element-using-query-sel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!