I am working on a project. Its looking like a blog site. In index page, i have added raty plugin for rate the article. When I rate a post, i am getting ratting value by click event. I need that article id & user id on click function of raty function. How can I get this ?
My HTML code :
<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">
<h2 class="book-title"><%= user[i].writeArticle[j].title%></h2>
<h4 class="book-writer">লেখাঃ <%= user[i].name%></h4>
<h4 class="book-writer">ছবিঃ সংগৃহীত</h4>
<h4 class="sub-level"><%= user[i].writeArticle[j].cetagory%></h4>
<h4 class="sub-level"> লেভেল :<span><%= user[i].writeArticle[j].label%></h4>
<span class="star"> </span>
</div>
My Jquery code:
$('.star').raty({
click: function(score, evt) {
var rating=score;
console.log(rating);
// need article title here:
}
});
You can add the id's as data-title-id and data-user-id attributes on the .star element. Then in the event handler you can do $(this).attr('data-title-id') to get the title id.
Edit example:
<span class="star" data-title-id="74">
Now in the click handler
$(this).attr('data-title-id')
Should return "74"