I am attempting to dynamically add and remove an input box based on the checkbox status. However, I am encountering some difficulties. One thing I am uncertain about is how to link the $this (div) with additional attributes.
HTML:
<form>
Lifetime Secs <input id="sec" type="checkbox" name="sec" value="sec" /> <br />
Lifetime KBytes <input id="kb" type="checkbox" name="kb" value="kb" />
</form>
JavaScript:
$("#sec, #kb").click(function() {
if ($(this).is(':checked')) {
$(this).after('<input type="text" name="input" id="inputbox" />');
} else {
$(this).next('input').remove();
}
});
JSFiddle: http://jsfiddle.net/felix001/eA32C/22/
Thanks,