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

302
Vistas
jquery get href in children()
  alert($(this).children().next().html());

returns

  <a href="thelink.php?id=XXXX">click me...</a>

How do I change above statement to grab only the href?

Have tried attr('href') but can't get it to work.

(Yes, jq-noob and no time.)

//edit - code added:

<div class="row">
  <div class="date">
    <h2>27</h2>
    <h3>dec</h3>
  </div>
  <h2><a href="/wpb/index.php?id=4192#4199">the title..</a></h2>
  <p>the description...</p>
</div>

jq invoked by:
$("#threecol .row").click(function() {  
  alert($(this).children().next().href);
});

regards,

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Find the attribute value using .attr('href').

EDIT: The first anchor within a H2:

alert($(this).find('h2 a:first').attr('href'));

You could also reference it via a class if you prefer and use the class in your anchor.

alert($(this).find('.myLink').attr('href'));
over 4 years ago · Santiago Trujillo Denunciar

0

$(this).children().next() is returning an element that has an <a> inside of it.
To get that <a>'s href, you need to select it, then call .attr('href').

You want to write something like

alert($(this).find('a:first').attr('href'));

In your case, you may want to write .find('h2 a').

over 4 years ago · Santiago Trujillo Denunciar

0

You can try this:

Edited: alert($(this).find("a").attr("href"));

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