I want to make the whole staff-container
linked to the first href inside of it. (The one in staff-picture
). How do I write this with jQuery? I'm pretty confused with attr()
and I know that I have to use it.
In the following HTML, the jQuery should make staff-container
linked to google.com.
<div class="staff-container">
<div class="staff">
<div class="staff-picture">
<a href="http://www.google.com/"><img src="img/people/teachers/ahmed.png" /></a>
</div>
<p><span class="bold">Mr. Ahmed</span><br />
Ext. 13417<br />
Room 417/323<br />
<a href="mailto:email@wcskids.net">email@wcskids.net</a></p>
</div>
</div>
EDIT: Thanks to the answers I used this jQuery:
$('.staff-container').click(function() {
window.location.href = $(this).find('a').attr('href');
});
If there is no link inside staff-picture
I do NOT want it to link the email. If jQuery can't find the link in staff-picture
, I want the click to do nothing.