Select all HTML elements with text

后端 未结 3 1803
無奈伤痛
無奈伤痛 2021-01-29 06:38

I have HTML document:

Some text

3条回答
  •  故里飘歌
    2021-01-29 07:34

    Here is another way (assuming the elements contain classes text and date)

    var coll = document.querySelectorAll(".text, .date"); //Get HTML elements having class .text and .date
    var elements = [].slice.call(coll); //Convert to array
    elements.map(function(el,i) { console.log(el.innerHTML.trim()) });   //Display element innerHTML using `map` function

    Some text

    23.12

提交回复
热议问题