What I would like to do is change an object's attribute, but for only that one. So something like, $('.up img').attr("src","img/up.png")
for the one that has been clicked, not all the elements that have .up img
.
jQuery:
$('.up img').click( function(){
var postDataUp = $(this).attr('mod');
$.post('/votePost.php', {varUp: postDataUp}, function(o){
console.log(o);
if(o == 1){
$('.up img').attr("src","img/up.png");
}else if(o == 2){
$('.up img').attr("src","img/up-g.png");
$('.down img').attr("src","img/dw.png");
}else if(o == 3){
$('.up img').attr("src","img/up.png");
}
}, 'json');
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…