私がやろうとしていること: td をクリックして、同じクラスの div を表示します。
$(document).ready(function(){
$("td").click(function () {
var target = $(this).attr("class");
$("div").show("slow"); //I want this div to have same class as target
});
});
$("div." + target).show("slow");
variable にクラスがありますtarget。$('div.class')したがって、div を表示するにはドット構文を使用します。
使用する
$("div." + target).show("slow");
あなたのコードは
$(document).ready(function () {
$("td").click(function () {
var target = $(this).attr("class");
$("div." + target).show("slow");
});
});
試す
$(document).ready(function () {
$("td").click(function () {
var target = this.className;
$("div." + target).show("slow");
});
});