Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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 answers
Answer question

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 Report

0

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

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!