I am having trouble changing the "text" between an HTML tag using jQuery. When someone clicks on a "radio button", the text should be updated in a certain HTML element. Here is my HTML:
<div class="radio-line" id="radio-manager">
<input type="radio" id="rad-400" name="radio-manager" value="No" />
</div>
HTML to be updated on radio check:
<h4 class="manager">Manager</h4>
When someone clicks on the radio above, the "Manager" text should become "Employees". I tried some jQuery code but cannot quite figure it out.
All you need to do is this -
$('input[name="radio-manager"]').change(function() {
if($('#rad-400').is(':checked')){
$('h4.manager').text('Employees');
} else {
$('h4.manager').text('Manager');
}
});
See http://jsfiddle.net/Eub9Y/
Check out the following fiddle.
http://jsfiddle.net/JBjXN/
<div class="radio-line" id="radio-manager">
<input type="radio" id="rad-400" name="radio-manager" value="No" data-text="Employees" />
</div>
<h4 class="manager">Manager</h4>
$('.radio-line').on('click', 'input[type="radio"]', changeText);
function changeText(e) {
$('.manager').text($(e.currentTarget).data('text'));
}
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