javascript - Linking a div to the href inside it -
i want make whole staff-container linked first href inside of it. (the 1 in staff-picture). how write jquery? i'm pretty confused attr() , know have use it.
in following html, jquery should make staff-container linked 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: answers used jquery:
$('.staff-container').click(function() { window.location.href = $(this).find('a').attr('href'); }); if there no link inside staff-picture not want link email. if jquery can't find link in staff-picture, want click nothing.
try this
$('.staff-container').click(function(e) { if($(this).find('a').attr('href')) window.location.href = $(this).find('a').attr('href'); e.preventdafault(); }); like this..??if want first anchor tag can give like
window.location.href = $(this).find('a').eq(0).attr('href');
Comments
Post a Comment