Assuming you are dealing with a single class per element:
function swapCssClass(a,b) {
while (document.querySelector('.' + a)) {
document.querySelector('.' + a).className = b;
}
}
and then call simply call it with
swapCssClass('x_visible','x_hidden');