-2

I want set star rating dynamic from database, i used below code and success to set value, but i not to set readonly status

jQuery on document ready

$('.raty').raty({
    readOnly: function () {
        return $(this).attr('data-read');
    },
    score: function () {
        return $(this).attr('data-rating');
    }
});

Html script 1st and 2nd row sample

<div class="raty" data-rating="3" data-read='false'>
<div class="raty" data-rating="4" data-read='true'>
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
Raj
  • 15
  • 1
  • 5

1 Answers1

0

Try this:

$('.raty').raty({
    readOnly: true,
    score: function () {
        return $(this).attr('data-rating');
    }
});

Updated answer:

html:

<div class="raty" data-rating="3" data-read='false'>
<div class="raty" data-rating="4" data-read='false'>

jquery:

$(".raty").each(function() {
  $(this).raty({
    readOnly: true,
    score: function () {
        return $(this).attr('data-rating');
    }
});
});
Joke_Sense10
  • 5,341
  • 2
  • 18
  • 22
  • thanks for reply, but above code will set readonly to all rows, i want to set readonly false to some rows. then??????? – Raj Nov 24 '13 at 05:16
  • @Joke_Senses10 i will have to add jquery for every id which is not proper way to solve my problem , and my code is not DOM Ready so Dynamically added jquery for each id will not work – Raj Nov 24 '13 at 05:27
  • This should solve your problem: http://stackoverflow.com/questions/15933121/how-to-control-target-in-a-multiple-jquery-raty-system – Joke_Sense10 Nov 24 '13 at 05:35
  • in that code readonly value set by default in jquery , which i want to set from html side for each row Like :
    – Raj Nov 24 '13 at 05:42
  • you have set readyonly=true; in jquery. but what should i change if i want to set readyonly=false; to some rows dynamically ??????? – Raj Nov 24 '13 at 05:50
  • Finnaly I solve this problem , i write two function like : > $('.raty_w').raty({ readOnly : false, > score: function(){ > return $(this).attr('data-rating'); > } }); > > $('.raty_r').raty({ readOnly : true, > score: function(){ > return $(this).attr('data-rating'); > } }); set separate class name 1st'raty_r' for readyonly:false; 2nd'raty_w' for readyonly:true;
    – Raj Nov 24 '13 at 06:00