jQueryに少し問題があります。私はかなり新しいので、私が何をしているのかを詳しく説明します。 私はjQueryを通して連続した数字でいっぱいになるいくつかのh1を持っています。jQueryで項目の選択を解除するにはどうすればよいですか?
<h1 class="number"><span></span></h1> *31
var date = 1;
$('.number').each(function() {
$(this).find('span').html(date);
date++;
});
私は.addClass("selected")
と、個々のh1
年代を選択することができますよ。
$('.number').click(function() {
$(this).toggleClass("selected");
});
問題は、複数の要素を選択できることです。理想的には、私は1つのアイテムを選択することができ、別のアイテムを選択すると、前のクラスは "が選択された"というクラスを失います。どうすればいい?
$('.number').click(function() {
// select the .number elements that have the class .selected and remove it from them
$('.number.selected').removeClass('selected');
// add it to this one
$(this).addClass("selected");
});
'unselect' ... – vsync