Skip to content

Instantly share code, notes, and snippets.

@walterjaworski
Created October 14, 2020 18:58
Show Gist options
  • Save walterjaworski/17903faa54f1cc472e3f0d7918643f68 to your computer and use it in GitHub Desktop.
Save walterjaworski/17903faa54f1cc472e3f0d7918643f68 to your computer and use it in GitHub Desktop.
// Verificando se existe alguma <img> no DOM que possua alguma palavra específica
// Lista as <img>
let oImg = document.getElementsByTagName('img')
// Caso a lista seja maior que 0
if (oImg.length > 0) {
// Transforma oImg, que é um html colection, em um array
let arr = Array.from(oImg)
// Lista o html de cada item do array
let imageList = arr.map((item) => { return item.outerHTML })
// Função que deixa a query, palavra escolhida, em lowercase e faz a busca por ela, em lowercase
const filterItems = (query) => {
// Retorna o objeto
return imageList.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) > -1)
}
// Faz a busca pela palavra housecrm.com.br
let fakeSearch = filterItems('housecrm.com.br')
// Imprime o resultado acima
console.log('fakeSearch value:',fakeSearch)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment