ivannaxara ivannaxara - 1 year ago 92
Javascript Question

jQuery on click redirect to child href attribute

I´m trying to link one div with the href attribute of his first href my html looks like this

<div class="clicked">
<a class="i-want-this-href" href="target">
<a class="this-one-is-useless" href="Wrong-target">

And I have tested some different ways like this:

aux= $('this:first-child').attr("href");

But I always get
on the console. And I want to get "target" inside the first

Any help will be preciated!

Answer Source

Your selector is incorrect, you can use .find()/.children() along with :first selector

aux= $(this).find('a:first').attr("href");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download