Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda