我试图通过一个元素的类来隔离它,但我需要类名的一部分来自变量,因为每个元素都有一个唯一的名称。
div class="post6453"
div class="post9845"
div class="post2345"
var id = $(this).attr("id"); (ID = 6453, 9845, 2345 for example)
if(data == 1){
$('post+ID').html("Html goes here");
}else{
$('post+ID').html("Html goes here");
}
我希望这是有道理的。谢谢
您的变量是id
(小写),而不是ID
。甚至您的变量串联也不正确。尝试
$('.post' + id).html(...)
如果元素是唯一的,则应使用ID="代替:
我想这是jQuery选择器
$(".post"+id).html("Html goes here");