我试图通过它的类来隔离一个元素,但我需要类名的一部分来自一个变量,因为每个元素都有一个唯一的名称。
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(...)
关于javascript - 将 JQuery 变量添加到 $ ('.class' ).html ("HTML");,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17671267/