我有这个html树的例子
<div class="auditions_date">
<div class="new_green above_deadline"><a href="/auditions/2 ?>">Contact</a></div>
<span class="aud_recommend"><a class="222" id="aud_recommend" href="#recommend_data">test</a></span>
</div>
<div class="auditions_date">
<div class="new_green above_deadline"><a href="/auditions/3 ?>">Contact</a></div>
<span class="aud_recommend"><a class="333" id="aud_recommend" href="#recommend_data">test</a></span>
</div>
当我点击test
链接时,我希望获得href
代码的a
attr
也许:
$('a#aud_recommend').on("click", function() {
var j = $(this).parent('.auditions_date').find('a').attr('href');
console.log(j);
});
这似乎没有正常工作..任何想法?
感谢
答案 0 :(得分:5)
$(document).ready(function () {
$('a#aud_recommend').on("click", function (e) {
//e.preventDefault();
var j = $(this).parents('.auditions_date').find('.new_green a').attr('href');
console.log(j);
});
});