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

270
Views
jquery obtener href en niños ()
 alert($(this).children().next().html());

devoluciones

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

¿Cómo cambio la declaración anterior para obtener solo el href?

Probé attr('href') pero no puedo hacerlo funcionar.

(Sí, jq-noob y sin tiempo).

//editar - código añadido:

 <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); });

Saludos,

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Encuentre el valor del atributo usando .attr('href').

EDITAR: El primer ancla dentro de un H2:

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

También puede hacer referencia a él a través de una clase si lo prefiere y usar la clase en su ancla.

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

0

$(this).children().next() devuelve un elemento que tiene un <a> dentro.
Para obtener el href de <a> , debe seleccionarlo y luego llamar a .attr('href') .

Quieres escribir algo como

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

En su caso, es posible que desee escribir .find('h2 a') .

over 4 years ago · Santiago Trujillo Report

0

Puedes probar esto:

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

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