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"
}
}