HTML でカスタムの「selected」属性を使用しようとしていますが、jQuery は常にこの属性の間違った値を返します。「selected」がオプションタグで使用されていることは知っていますが、他のタグで使用できないのはなぜですか? 例を参照してください: http://jsfiddle.net/SE7FB/8/
<div class="category" selected="false">First</div>
<div class="category" selected="false">Second</div>
<div id="tester" style="width: 100px; height: 100px; float: right; background-color: black;"></div>
JavaScript:
$(".category").click(function () {
$("#tester").css("background-color", "rgb(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ")");
$("#tester").append("<p>" + $(this).attr("selected") + "</p>");
if ($(this).attr("selected") == "true") {
$(this).css("background-color", "transparent");
$(this).attr("selected", "false");
} else if ($(this).attr("selected") == "false") {
$(this).css("background-color", "blue");
$(this).attr("selected", "true");
}
});