我使用下面的代碼嘗試從另一個元素獲取href數據,它不斷返回「undefined」我做錯了什麼?從兄弟的孩子jQuery獲取href屬性?
$('.linkbutton').bind('click', function(e) {
e.preventDefault();
var flagURL = $(this).siblings().next('.flag-action').attr('href');
console.log(flagURL);
});
<div class="linkbutton">
<h4 class="quoteflag">
<a href="/demo/url/here" title=" " class="flag-action">
</a>
</h4>
'兄弟姐妹()'給你從同一拉特作爲選定元素的所有元素,所以你選擇'.linkbutton'嘗試從同一拉特選擇所有元素,然後選擇帶有標誌動作類的下一個元素,詳細瞭解https://api.jquery.com/siblings/和https://api.jquery.com/each/ – Sojtin