Extract text from HTML while preserving block-level element newlines

后端 未结 5 1627
难免孤独
难免孤独 2020-12-13 18:28

Background

Most questions about extracting text from HTML (i.e., stripping the tags) use:

jQuery( htmlString ).text();

While this

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 19:10

    Use element.innerText This not return extra nodes added from contenteditable elements. If you use element.innerHTML the text will contain additional markup, but innerText will return what you see on the element's contents.

提交回复
热议问题