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

154
Vistas
Using Jquery to append to all href and src attributes

I need to append the name of my github repository to the beginning of all href and src attributes. Any help is appreciated.

<script>
  $(document).ready(function() {
    $(src).attr('src', '/Demo_App').each();
    $(href).attr('href', '/Demo_App').each();
});
</script>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

  1. Select all nodes on the DOM with
document.getElementsByTagName('*')
  1. Loop through them. If has src, update the src with repo name in front. If href, do the same thing but with the href instead.

const repoName = '/Demo_App';

window.addEventListener('load', () => {
    const all = document.getElementsByTagName('*');

    for (const node of all) {
        const src = node.getAttribute('src');
        const href = node.getAttribute('href');

        if (src) node.setAttribute('src', `${repoName}${src}`);
        if (href) node.setAttribute('href', `${repoName}${href}`);
    }
});
<body>
    <a href="https://google.com"></a>
    <img src="https://google.com" />
    <a href="https://google.com"></a>
    <img src="https://google.com" />
    <a href="https://google.com"></a>
    <img src="https://google.com" />
    <a href="https://google.com"></a>
    <img src="https://google.com" />
</body>

about 4 years ago · Juan Pablo Isaza Denunciar

0

use jQuery's attr() with a callback function to append values.

For example

const suffix = "/Demo_App";

// all elements with `src` attribute
$("[src]").attr("src", (_, src) => src + suffix)

// all elements with `href` attribute
$("[href]").attr("href", (_, href) => href + suffix)

As always you might not need jQuery

const suffix = "/Demo_App";

document.querySelectorAll("[src]").forEach(elt => {
  elt.src += suffix
})

document.querySelectorAll("[href]").forEach(elt => {
  elt.href += suffix
})
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