ajax - Change a distinct attribute from a group using Jquery -
i have scheme implemented page displays bunch of user posts. works well, i'm having problem getting image alter after user presses it. have function called likesystem fires when user clicks like: (formatted returned json array)
<img src='img/star.png' id='like"+data.id+"' height='24' onclick='likesystem("+data.id+",1);'/> // 1 indicates type of post.
so fires , response info shot ajax , sent through this.
function likesystem (postid,type) { ///working ajax phone call here.....and then.... var imagechange = "#like" + postid; if(data==1) { //like successful $(imagechange).attr("src","img/unstar.png"); } else { //unlike successful $(imagechange).attr("src","img/star.png"); }
so problem having changing star image unstar image , vis versa on right post. tried setting own variable imagechange combination of , postid hasn't been working?
anyone know how correctly?
got working $("#like" + postid).attr("src","img/unstar.png");
jquery ajax
No comments:
Post a Comment