以下の関数のコメントの指示に従って、クラス 'piece' のすべてのメンバーを選択し、(:even :odd セレクターを使用して) 半分に分割し、2 つの異なるクラスをそれらに追加しようとしました。しかし、各クラスのメンバーが 0 人であるというエラー メッセージが表示されます。それらを間違って選択しましたか?
function setUpPieces() {
//select all the divs with class 'piece'
//add the 'light' class to half of them
//add the 'dark' to the other half
$('.piece:even').addClass('light');
$('.piece:odd').addClass('dark');
}
アップデート:
これらは指示です
The jQuery selectors :even and :odd may be useful.
An example:
$('div:even')
selects half of the divs on the page: the first one (the one at index 0) and then every second div after it (the ones at indicies 2,4,6 ...)
$('div:odd')
selects the other half.