Instead of using the onclick
attribute, it is much cleaner to add the event listener in JavaScript, like so:
$('#lightOn').on('click', function() {
$("#lightOn").addClass("active");
$("#lightOff").removeClass("active");
socket.emit("setting", {"light":"on"});
});