Hmmm, a very basic solution I can think for this is to store the last applied class in a variable, then remove that before applying the new class. Something along this line:
var lastBg = "";
$('.boxedBgSwitch').on('click', function (e) {
e.preventDefault();
var bgClass = $(this).data("id");
$('body').removeClass(lastBg).addClass(bgClass);
lastBg = bgClass;
});
Can't say this is the best solution, but it seems to work reliably, and won't break even if you start changing up class names. Here's a JSFiddle to demonstrate it in action. Hope this helps! Let me know if you have any questions.