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.
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
Post a Comment