I added a fontawesome icon to my HTML as a button and now I want to use JavaScript to trigger it AJAX style
<a href="#"><i id="heart" class="jam jam-heart-f"></i> Like</a>
Below is the JavaScript code I attempted to use to trigger it, but I haven't encountered any errors. My goal is to post the 'like' attempt to a PHP page called like.php in order to add the link to a database.
$(document).ready(function()
{
$('body').on("click",'#heart',function()
{
var videoId = "<?php echo $video_id; ?>";
var A=$(this).attr("id");
var B=A.split("like");
var messageID=B[1];
var C=parseInt($("#likeCount"+messageID).html());
$.ajax({
method: 'POST',
url: 'like.php',
data: {videoId: videoId},
cache: false,
success: function(result){
likeInfo = JSON.parse(result);
$("#likeCount1").html("Likes:" + likeInfo.likeCount);
//document.getElementById("likeCount1").value = likeInfo.likeCount;
//$("#likeCount1").html(likeCount);
}
});
}
});
Despite setting #heart as the target in JS using the id="heart" with the font awesome icon, it doesn't seem to be triggered. Any suggestions on how I can solve this issue?