私は次のようなチェックボックスを備えたリストをたくさん持っています:
<ul>
<li><label class="highlight"><input type="checkbox" id="1" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="223" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="32" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="42" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="54" class="filteritem">Lorem Ipsum</label</li>
</ul>
<ul>
<li><label class="highlight"><input type="checkbox" id="43" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="343" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="342" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="53" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="55" class="filteritem">Lorem Ipsum</label</li>
</ul>
すべてのチェックボックスには一意のIDがあります
チェックしたときにラベルの背景色を切り替えたい。
これは私が得たものですが、機能しません:
jQuery:
$(".filteritem").click(function(){
$(this).toggleClass('highlight');
});
CSS:
.highlight {
//change something
}