I've created a jQuery function that copies checkbox values to the textarea with the ID #msg.
$(document).ready(function(){
$("input:checkbox").click(function() {
var output = "";
$("input:checked").each(function() {
output += $(this).val() + "";
});
$("#msg").val(output.trim());
});
});
Currently, clicking any checkbox will copy its value to the #msg field. How can I modify this so that only checkboxes within a <ul>
or specific div are affected?
For example:
<ul>
<input name="foo2" type="checkbox" value="Hello" id="tel_1">
<label for="tel_1">Hello</label>
</ul>
Copy the above code to the #msg
textarea, but do not copy the following:
<input name="foo" value="123123123" id="tel_11" type="checkbox">
<label for="tel_11">Alan</label>
I tried modifying the selector from $("input:checkbox")
to $("ul:input:checkbox")
, but it didn't work as intended.