I have a page with raty divs. With the classic code $('.raty').raty({...});
the plugin works perfectly on these existing divs. But when I load new raty divs thanks to an ajax function, new divs are "not transformed into stars". Could you please help me to find my mistake ?
$.ajax({
url: '/ws/player/reviews/p/1',
context: document.body,
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "jsonpCallbackfunction",
success: function(data) {
$.each(data.response.reviews, function( key, value ) {
html = '';
html += '<div class="raty read" data-rating="5"></div>';
$('#reviews').append(html);
});
}
data: {player_id: player_id, from: $('#reviews').data('from')}
}).done(function() {
$(this).find('.raty').raty({
path: '/img/raty/',
readOnly: true,
score: function() {return $(this).data('rating');}
});
});
Although, if I try $(this).find('.raty').html('blablabla');
"blablabla" is correctly written in all my '.raty' divs.
Thank you for you help,
Jeremy
you have done little mistake
$.ajax({
url: '/ws/player/reviews/p/1',
context: document.body,
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "jsonpCallbackfunction",
success: function(data) {
$.each(data.response.reviews, function( key, value ) {
html = '';
html += '<div class="raty read" data-rating="5"></div>';
$('#reviews').append(html);
});
}
data: {player_id: player_id, from: $('#reviews').data('from')}}).done(function() {
$(this).find('#reviews .raty').raty({ // Changes
path: '/img/raty/',
readOnly: true,
score: function() {return $(this).data('rating');}
});});
Hope, this code will work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With