next()
作品は、あなたの構造では、<a>
は一人っ子<h1>
であり、その技術的に<a>
として何も返さないだろうnext()
は<h1>
の唯一の息子である呼び出します。あなたがドキュメントを引用<h1>
を削除する場合はそれゆえ、なぜそれが動作します: Get the immediately following sibling of each element in the set of matched elements. If a selector is provided, it retrieves the next sibling only if it matches that selector.
http://api.jquery.com/next/
nextUntil()
は、ドキュメントを引用し、要素までのセレクタから始まるが、引数として指定されたセレクタを除くのセットを取得します:クエリについてhttp://api.jquery.com/nextUntil/
Get all following siblings of each element up to but not including the element matched by the selector, DOM node, or jQuery object passed.
、あなたnext()
に電話する前に.parent()
に電話して、親の兄弟を取得していることを確認してください。彼の叔父)
<script>
$(document).ready(function() {
$('a.link').click(function() {
var element = $(this).parent().next();
alert(element.attr('class'));
});
});
</script>
1良い答え、完全なソリューションを使用しています。 –
+1叔父を使用するための+1 – ansiart