Reputation: 21
I want to get data-id from html but when i click on the link i got this error..! Comment_id is not defined here is my html code
<a href="javascript:void(0)" data-id="<?php echo $row->video_comment_id ?>" data-action="<?php echo site_url('videosd/commentslike');?>" class="video_comment_like">
like
</a>
I am fetching $row->video_Comment_id
from data base.
Here is my jQuery code
$('.video_comment_like').click(function(){
var coment_id = $(this).data("id");
console.log(comment_id)
});
and i also tried $(this).attr('data-action');
but its not working.
Upvotes: 0
Views: 301
Reputation: 32354
Use the attr() function
$('.video_comment_like').click(function(){
var comment_id = $(this).attr("data-id");
console.log(comment_id);
});
Upvotes: 0
Reputation: 31749
Its a typo coment_id
& comment_id
-
var comment_id = $(this).data("id");
console.log(comment_id);
Upvotes: 2