Use classes to indicate what MathJax should typeset. Exclude body, then include e.g. div.content or possibly .mathjax. That way you can activate and deactivate by manipulating the .classList.
Here in the docs we see
MathJax = {
options: {
skipHtmlTags: [ // HTML tags that won't be searched for math
'script', 'noscript', 'style', 'textarea', 'pre',
'code', 'annotation', 'annotation-xml'
],
includeHtmlTags: { // HTML tags that can appear within math
br: '\n', wbr: '', '#comment': ''
},
ignoreHtmlClass: 'tex2jax_ignore', // class that marks tags not to search
processHtmlClass: 'tex2jax_process', // class that marks tags that should be searched
compileError: function (doc, math, err) {doc.compileError(math, err)},
typesetError: function (doc, math, err) {doc.typesetError(math, err)},
renderActions: {...}
}
};
so we can add nomathmax to the <body> element, and then mathjax to e.g. <div class='content mathjax'.
We can also detect and demand load MathJax and AbcJs once a page needs them (and keep them loaded).