-1

I cannot find out why this image source is not working. only last one is working fine(like 4 :text only).

Honestly speaking I'm not a jquery expert even don't have a bit idea about it and cannot find out what should I change.

if (reaction == 1) {
  $("#like1post" + post + "user" + user).attr("src", "helloone.png");
  $("#like2post" + post + "user" + user).attr("src", "hellotwo.png");
  $("#like3post" + post + "user" + user).text("<img src='hellothree.png'>");
  $("#like4post" + post + "user" + user).text("Like 4");
  $("#likeCountPost" + post).text(data);
echo "<button id='like1post" . $post . "user" . $user . "' onclick='likeFunction(1, " . $post . ", " . $user . ")'>
<img src='logo/likedone.png' width='20'>
</button>";
Sakib
  • 13
  • 5

1 Answers1

0
<?php
$post=1;
$user=1;
echo "<button id='like1post" . $post . "user" . $user . "' onclick='likeFunction(1,".$post.",".$user.")'><img src='https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcRljWQ9H3Rtxh14io6tof4fDRgDnkU7JCQL9cLqhPGOFR3NEUGO' width='20'></button>";
?>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
     $(document).ready(function(){   
     });
     function likeFunction(num,post,user)
     {
        $("#like1post" + post + "user" + user +" img").attr("src", "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQdTEzB10rZPcdhjWzjv5TWs83Y7s-iRex6VefSy8pfRNwVV09e");
     }

</script>

I have just tried with only 1 button of yours... Try this. You are creating image in button.. so the image attr should be added to image only

Amanjot Kaur
  • 2,028
  • 4
  • 18
  • 33