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

177
Views
How can I select all the link which have an image child

I am using the following to add a _blank target attribute to all my external links

$.expr[':'].external = function(obj) {
    return (obj.hostname != location.hostname) && obj.href.startsWith("http");
};

$('a:external').attr('target', '_blank');

Now, I would like to do similarly for all links that are parent to images.

<a href="..."><img></a>

How can I build a selector to target these instances?

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

0

To target elements which contain another specific element you can use the :has() selector:

$('a:has(img)').prop('target', '_blank');

Also, just as an aside, the :external selector logic can be made more succinct with an arrow function:

$.expr[':'].external = obj => (obj.hostname != location.hostname) && obj.href.startsWith("http");
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!