To evaluate math on the page after MathJax has processed it, you need to queue a call to Typeset
via MathJax.Hub.Queue(["Typeset", MathJax.Hub, el])
where el
is the element containing the math that needs to be evaluated:
function newFrac() {
a1 = ran(1,20);
a2 = ran(1,20);
var txt = "$ \frac{"+a1+"}{"+a2+"} $"
var el = document.getElementById("a");
el.innerHTML=txt;
MathJax.Hub.Queue(["Typeset", MathJax.Hub, el]);
}
See Modifying Math on the Page for more detail. See the section on Manipulating Individual Math Elements if you want to change an existing equation.