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
jQuery .not() function not working within .parent() function

I'm trying to add a class to links within paragraphs whose paragraphs don't have immediate text, but the class is being added to every link.

This is what I tried so far:

$('.card p a').each(function() {
  if ($(this).parent().not($(this)).text()) {
    $(this).addClass('noTextDecoration');
  }
});
.noTextDecoration {
  text-decoration: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="card">
  <p>Curabitur aliquet quam id <a href="#">dui posuere blandit</a>. Vivamus magna justo, lacinia eget consectetur sed, convallis at tellus. Nulla porttitor accumsan tincidunt.</p>
  <p><a href="#">learn more</a></p>
</div>
<div class="card">
  <p>Curabitur aliquet quam id <a href="#">dui posuere blandit</a>. Vivamus magna justo, lacinia eget consectetur sed, convallis at tellus. Nulla porttitor accumsan tincidunt.</p>
</div>

Thanks in advance!

about 4 years ago · Santiago Trujillo
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!