Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

get-visible-text

LinusU177MIT1.0.0-rc.1

Retreives the visible text of a DOM Element.

readme

Get Visible Text

Retreives the visible text of a DOM Element.

Installation

npm install --save get-visible-text

Usage

const getVisibleText = require('get-visible-text')

// <div>Hello,   <span>World<span>!</div>
getVisibleText(document.querySelector('div'))
//=> Hello, World!

The function can also be used with Puppeteer:

const getVisibleText = require('get-visible-text')
const puppeteer = require('puppeteer')

(async () => {
  const browser = await puppeteer.launch()
  const page = await browser.newPage()

  await page.goto('https://example.com')

  const h1 = await page.$('h1')
  const text = await page.evaluate(getVisibleText, h1)

  console.log(text)
  //=> Example Domain

  await browser.close()
})()