多くのセクション要素を含むdivでソート可能なjqueryを使用しています。index() を使用して各セクションの位置を出力したいと思います。
index() は最初のセクションの値のみを返しますが、2 番目のセクション (または 3 番目、4 番目など) を見つけることができません。
何が間違っているのかわかりません。どんな助けでも大歓迎です。これが私のコードです:
<div id="existingquestions" class="sortable">
<section class="question" id="question_777">
<p id="positionof_777"></p>
<p class="questiontext">question.text</p>
<script>$(document).ready(function() {
var qpos = Number($('.sortable > section:visible').index('#question_777')+1);
$('#positionof_777').html(qpos);
});
</script>
</section>
<section class="question" id="question_888">
<p id="positionof_888"></p>
<p class="questiontext">question.text</p>
<script>$(document).ready(function() {
var qpos = Number($('.sortable > section:visible').index('#question_888')+1);
$('#positionof_888').html(qpos);
});
</script>
</section>
</div>
私が使用している他の機能は、基本的に上記と同じですが、問題なく動作します。
$(document).ready(function() {
$('input').placeholder();
$(".sortable > section:visible").hover(function() {
var index = $(this).index()+1;
$("#example_index").html("Index " + index);
});
});
私は無知です。最初の例で何が間違っていますか?