jQuery - Problem loading new image src -


** edit **

image showing needed done. when admin clicks on unapproved (x) comment automatically approves , image changed check mark , vice versa.

enter image description here

i using following jquery code, having problems loading new image src on click.

<script> $(document).ready(function(){    $(".disapprovecomment").click(function() {     var id = $(this).children("p").text();     $.ajax({                 type: "post",         url: "/comments/disapprovecomment/"+id,         async:false,         success: function(msg){             //using $(this).(".disapprove")... not work             $(".disapprove").attr("src","/img/icons/approve.png");         }     }); }); }); </script> 

this view file

<?php     if($comment['comment']['approved'] == 1){         echo '<div class="disapprovecomment"><p style="display:none">';         echo $comment['comment']['id'];         echo '</p><img class="disapprove" src="/img/icons/approve.png" border="0">';         echo '</div>';     }else{         echo '<div class="approvecomment"><p class="idanchor" style="display:none">';                    echo $comment['comment']['id'];         echo '</p><img class="approve" src="/img/icons/disapprove.png">';         echo '</div>';     }        ?> </td> 

if $(this).(".disapprove").attr... nothing updated. if leave in code, element images in class names gets updated. appreciated...

in ajax callback have context need hold context ealier in varaible.

<script> $(document).ready(function(){    $(".disapprovecomment").click(function() {     var comment = $(this);     var id = $(this).children("p").text();     $.ajax({                 type: "post",         url: "/comments/disapprovecomment/"+id,         async:false,         success: function(msg){             //using $(this).(".disapprove")... not work             comment.find(".disapprove").attr("src","/img/icons/approve.png");         }     }); }); }); </script> 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -