javascript - Change innerhtml of label when radio button is checked -
i want add innerhtml label, when radio button checked. default label not have value.
i want change value of label based on value of radio button.
want define own value this. label value 1 should be: "label 1"
label value 2 should "label 2" etc.
i use star rating, when next radio button checked, should remove value of previous label.
this current html:
<ul class="rating"> <li> <span class="ratingselector"> <input type="radio" name="ratings[1]" id="degelijkheid-1-5" value="1" class="radio"> <label class="full" for="degelijkheid-1-5"></label> <input type="radio" name="ratings[1]" id="degelijkheid-2-5" value="2" class="radio"> <label class="full" for="degelijkheid-2-5"></label> <input type="radio" name="ratings[1]" id="degelijkheid-3-5" value="3" class="radio"> <label class="full" for="degelijkheid-3-5"></label> <input type="radio" name="ratings[1]" id="degelijkheid-4-5" value="4" class="radio"> <label class="full" for="degelijkheid-4-5"></label> <input type="radio" name="ratings[1]" id="degelijkheid-5-5" value="5" class="radio"> <label class="full" for="degelijkheid-5-5"></label> </span> </li> <li> <span class="ratingselector"> <input type="radio" name="ratings[2]" id="design-1-5" value="1" class="radio"> <label class="full" for="design-1-5"></label> <input type="radio" name="ratings[2]" id="design-2-5" value="2" class="radio"> <label class="full" for="design-2-5"></label> <input type="radio" name="ratings[2]" id="design-3-5" value="3" class="radio"> <label class="full" for="design-3-5"></label> <input type="radio" name="ratings[2]" id="design-4-5" value="4" class="radio"> <label class="full" for="design-4-5"></label> <input type="radio" name="ratings[2]" id="design-5-5" value="5" class="radio"> <label class="full" for="design-5-5"></label> </span> </li> </ul>
try solution acc. you.
you can combile "label" string rvalue variable. i.e var rvalue="label"+$(this).attr('value');
like as:
$('.radio[name="rating[2]"]').change(function(){ var rvalue=''; if($(this).attr('value')=='1') { rvalue='bad'; } else if($(this).attr('value')=='5') { rvalue='amazing'; } $(this).parent('.ratingselector').find('.full').html(''); $(this).next('label').html(rvalue); });
working example: http://jsfiddle.net/7wlbyn2c/4/
Comments
Post a Comment