Reputation: 77
I need to change the label text on a radio button when it is selected from "Set default" to "default" - How can this be done with jQuery? I presume that you would use the class radio-default
as the selector but I don't know much about jQuery.
<div class="radio-default">
<input type="radio" id="line-radio-1" name="line-radio">
<label for="line-radio-1">Set default</label>
</div>
<div class="radio-default">
<input type="radio" id="line-radio-2" name="line-radio">
<label for="line-radio-2">Set default</label>
</div>
<div class="radio-default">
<input type="radio" id="line-radio-3" name="line-radio">
<label for="line-radio-3">Set default</label>
</div>
Upvotes: 2
Views: 13591
Reputation: 960
Try this
$('input:radio').click(function() {
$('label').text('Set default');
$(this).next('label').html('Default');
});
Upvotes: 0
Reputation: 2977
Do this:-
var $radioButtons = $('.radio-default input:radio[name="line-radio"]');
$radioButtons.change(function(){
if($(this).val() == 'on'){
$radioButtons.siblings('label').text('Set default');
$(this).siblings('label').text('default')
}
});
Working JsFiddle here
Upvotes: 1
Reputation: 15403
Try
$("input[name='line-radio']").click(function() {
$('.radio-default label').text('Set default');
if(this.checked){
$(this).next().text('default');
}
});
Upvotes: 4
Reputation: 1055
Use below script
$( "input:radio" ).click(function() {
$(':radio').each(function() {
$("#"+this.id).next().text( "Set default" );
});
$("#"+this.id).next().text( "Default" );
});
Upvotes: 2
Reputation: 505
you may want to reset the text on the previoused button clicked, but this can help you:
$('.radio-default').on('click',function(){
$(this).find('label').text("set");
})
Upvotes: 0
Reputation: 1214
You can add an on click hadler on the radio button
<input type="radio" id="line-radio-1" name="line-radio" onClick="yourFunc">
yourFunc: function(e){
$(e).next('label').text('your text');
}
Upvotes: 0