if ($("#" + id).attr("checked") == true) { if (!elems.includes(val)) { elems.push(val) } ...