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

112
Views
How to make post excerpt as link using Javascript?

I want to make a post excerpt into a clickable link.

And structure of my website is as follows.

  <div class="post_widget">
    <a class="poast_thumbnail" href="example.com">
        <div class="thumbnail>
                <img ...>
        </div>
    </a>
    <div class="post">
        <div class="title">
            <a href="example.com">this is sample</a>
        </div>
        <div class="post_excerpt">
          <p> == $0
            "Hello world"
            ::after
          </p>
          <a class="read_more" href="https://example.com">read more</a>
        </div>
    </div>
   </div>

I found the following JavaScript and modified it to suit my website.

<script>
const postExcerpts = document.querySelectorAll('.post .post_excerpt');

postExcerpts.forEach(postExcerpt => {
    const postUrl = postExcerpt.parentNode.querySelector('.title a').href;
    postExcerpt.addEventListener('click', () => {
        window.location.href = postUrl;
    });
});
</script>

I've changed .querySelector several times and tested it, but not working.

No errors appear in the chrome developer tools.

I'd like to hear some advice on which part I need to fix.

const postExcerpts = document.querySelectorAll('.post .post_excerpt');

postExcerpts.forEach(postExcerpt => {
    const postUrl = postExcerpt.parentNode.querySelector('.title a').href;
    postExcerpt.addEventListener('click', () => {
        window.location.href = postUrl;
    });
});
<div class="post">
    <div class="title">
        <a href="example.com">this is sample</a>
    </div>
    <div class="post_excerpt">
        <p>hello world</p>
    </div>
</div>

about 4 years ago · Juan Pablo Isaza
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!