Как взять текст скриптом через .text?

https://toster.ru/q/288693?e=3429912

by Mahmoud Elmahdi

HTML

<div>
  <label class="element-invisible" for="edit-submitted-fio">ФИО </label>
  <span class="field-prefix"></span> Тест тест тест
  <span class="field-suffix"></span>
</div>

JavaScript

$.fn.plainText = function() {
  var str = '';
  this.contents().each(function() {
    if (this.nodeType == 3) {
      str += this.textContent || this.innerText || '';
    }
  });
  return str.trim();
};
var output = $('div').plainText();
console.log(output);