Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to use MathJax to display some math that's been written in LaTex. I've put the MathJax script ( ) in the header, so everything loads just fine when the webpage first starts. But I need to be able to use this script with an onscreen button, rather than only in the header, so it will display LaTex that's been written after the site initially loads.

Here's the code for a button I've created that prompts the user, which is where I'm trying to put the script (don't mind that it says "myFavouriteColour"):

<p id="favouriteColour"></p>

function myFavouriteColour() {
    var colour = prompt("Enter your favourite maths!", "2x^3");
    if (colour != null) {
        document.getElementById("favouriteColour").innerHTML = "$$" + colour + "$$";
        alert(colour);
    }
}


What I have tried:

I've already tried putting in the MathJax script in a few ways. It usually just breaks the window prompt. Here's one of them:

<script>
function myFavouriteColour() {
    var colour = prompt("Enter your favourite maths!", "2x^3");
    if (colour != null) {
        document.getElementById("favouriteColour").innerHTML = "$$" + colour + "$$";
        alert(colour);
        script.src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-MML-AM_CHTML"
    }
}
Posted
Updated 14-Aug-18 7:32am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900