jQuery - Append a Value to a INPUT, keeping it a Comma Delimited list -
i have input follows:
<input type="hidden" id="attachment-uuids" value=""> i'd able append value input, @ different times:
$('#attachment-uuids).val('55555'); results in:
<input type="hidden" id="attachment-uuids" value="55555"> but doing:
$('#attachment-uuids).val('66666'); results in:
<input type="hidden" id="attachment-uuids" value="66666"> where i'd following:
<input type="hidden" id="attachment-uuids" value="55555, 66666"> how can append values when value empty , when value not empty comma delimited list?
thanks
$('#attachment-uuids').val(function(i,val) { return val + (!val ? '' : ', ') + '66666'; }); edit: @mkoryak noted, i'm doing unnecessary negation of val in conditional operator. rewritten without ! as:
(val ? ', ' : '')
Comments
Post a Comment