jquery - Run 'change' function from another element -
i have function runs when checkbox changed (works fine):
// event management $("input.box[type=checkbox]").change(function() { var name = $(this).attr("name"); $("input:checkbox[name='$name']").attr("checked", true); $.cookie(name, $(this).prop('checked'), { path: '/', expires: 365 }); });
<input id="<?php echo the_id();?>" type="checkbox" name="<?php echo the_id();?>">
i want able change state of checkbox button:
<a onclick="$('#<?php echo the_id();?>').attr('checked', true);">test</a>
this change checkbox not run change function.
any ideas? thanks
as you've discovered, setting checked
attribute programmatically not fire events. can manually using change()
:
<a onclick="$('#<?php echo the_id();?>').attr('checked', true).change();">test</a>
note trigger('change')
work too.
Comments
Post a Comment