Here is a sample that should do something like what you are after.
<!DOCTYPE html>
<html>
<head>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'],['\\(','\\)']]}
});
MathJax.Hub.Queue(function () {
document.getElementById("toggle").disabled = false;
});
</script>
<script>
var isTypeset = true;
function ToggleMJ(button) {
button.disabled = true;
button.value = (isTypeset ? "Typeset Math" : "Remove Typeset Math");
MathJax.Hub.Queue(
(isTypeset ? RemoveMJ : ["Typeset",MathJax.Hub]),
function () {
isTypeset = !isTypeset;
button.disabled = false;
}
);
}
function RemoveMJ() {
var jax = MathJax.Hub.getAllJax();
for (var i = 0, m = jax.length; i < m; i++) {
var tex = jax[i].originalText;
var isDisplay = (jax[i].root.Get("display") === "block");
if (isDisplay) tex = "$$"+tex+"$$"; else tex = "$"+tex+"$";
var script = jax[i].SourceElement();
jax[i].Remove();
var preview = script.previousSibling;
if (preview && preview.className === "MathJax_Preview")
preview.parentNode.removeChild(preview);
script.parentNode.insertBefore(document.createTextNode(tex),script);
script.parentNode.removeChild(script);
}
}
</script>
</head>