Reputation: 21
i have a checkbox array name "skills[]" and i want add a text to side of clicked(checked) checkbox(whithout Submit) my code like this:
<li><input name="skills[]" class="skills" value="1" type="checkbox" /></li>
<li><input name="skills[]" class="skills" value="2" type="checkbox" /></li>
wutdo? Thanks,
Upvotes: 1
Views: 65
Reputation: 1901
$('input.skills').on('change', function() {
if($(this).is(':checked'))
{
$(this).parents('li').append('<span class="text">your text</span>');
} else {
$(this).parents('li').find('.text').remove();
}
});
Working jsfiddle: http://jsfiddle.net/V3TZn/4/
Upvotes: 1
Reputation: 3600
Try this: DEMO
$("input[name='skills[]']").change(function(){
if($(this).is(':checked')){
$(this).parents('li').append('<span class="text">your text</span>');
}
else {
$(this).parents('li').find('.text').remove();
}
});
Upvotes: 0