Is there a way to make this code smaller into 1 block?
$('#product INPUT:checked').each(function () {
data.box1.push({
id: $(this).attr("id")
});
});
$('#product .dropSelect OPTION:selected').each(function () {
data.drops.push({
value: $(this).val()
});
});
$('#product .setSelect OPTION:selected').each(function () {
data.set.push({
value: $(this).val()
});
});
Well, you can combine the second and third blocks easily using a test:
While this isn’t much shorter, it has the advantage of saving jQuery the trouble of selecting elements using classes, which is more intensive than selecting IDs or tags. By testing the existence of a class on a single element instead of on the entire document, you should improve your overall performance. (Granted it probably won’t be a noticeable improvement, but optimization is rarely a bad thing.)