Javascript and mathjax ascii

104 Views Asked by At

I have a problem, I want to add numbers using a 'textbox' to add my formula math, but it won't render it

<p style="text-align:center; font-size:40px;">
`int ax^n dx `
</p>
Input nilai a : <input type="text" id="a" value="10">
Input nilai n : <input type="text" id="n" value="5">
<button onclick="coba()">OK</button>
<div id="tampil"></div>

    <script>
    function coba(){
    var a= document.getElementById("a").value;
    var n= document.getElementById("n").value;
    var e= "`int"+ a +"x^"+ n + "dx`"
    var f= a+n;
    document.getElementById("tampil").innerHTML= e;
    }
    </script>
1

There are 1 best solutions below

0
On

You need to tell MathJax that new math has been added to the page after you set the innerHTML. Do that by adding

MathJax.Hub.Queue(["Typeset",MathJax.Hub,"tampil"]);

after you set the innerHTML.

See the documentation for more details.