Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
Trying to pull H3 text using JS

I am trying to create a Google tag manager JS variable to pull the article name when someone clicks on it.

enter image description here

I need to pick up just the title (in red) but not " Home Sellers "

document.getElementsByClassName("blog-listing-post__summary blog-listing-post__summary--big")[0].querySelector("H3").innerText

returns:'HOME SELLERS\nWhich Home Appliances are Included with a Sold Property?'

How can I skip "home sellers" and pull value just under?

Thank you!

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Try using the split() and slice() methods. This will return an array that you can reference.

let x = 'HOME SELLERS\nWhich Home Appliances are Included with a Sold Property?';

let y = x.split('\n').slice(1);

console.log(y);
console.log(y[0]);

about 4 years ago · Juan Pablo Isaza Relatório

0

const h3 = document.querySelectorAll('h3').at(-1).innerText
about 4 years ago · Juan Pablo Isaza Relatório

0

If you want all and only the top level text, you just need to filter the H3's childNodes to get only text nodes and then join all the text together. The solution below should work in most cases.

const myHeadline = document.getElementsByTagName('h3')[0];
const myHeadlineTopLevelText = [...myHeadline.childNodes].filter(node=> node.nodeType === 3).map(node=>node.textContent).join("").trim();
console.log(myHeadlineTopLevelText);
<h3>
<span>sub text</span>
Main text
</h3>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda