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

300
Views
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 answers
Answer question

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 Report

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 Report

0

You can try this:

Edited: 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!