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

319
Views
querySelectorAll with including AND excluding attribute conditions (both)

The task is to find all elements which have values in "href" attribute, which suit 2 conditions at the same time:

  1. they contain :// string
  2. they not starting with http://internal.com string

So I need something like

const targetHrefs = document.querySelectorAll('[name="list"] ~ ul > li > a[href*="://"][href^="http://internal.com"]');

where the 2nd condtion should be with operator NOT

Is it possible using the only CSS Selector rule?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just put it in a :not?

const targetHrefs = document.querySelectorAll('a[href*="://"]:not([href^="http://internal.com"])');
console.log(targetHrefs.length);
console.log(targetHrefs[0]);
<a href="foo"></a>
<a href="https://example.com/"></a>
<a href="http://internal.com/"></a>

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!