Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
TypeError: Cannot read properties of undefined, when trying to load MathJax to a div

I'm building a system that generates equations and math exercises for the user. The client sends a GET request to fetch the exercise, and the server responds with the appropriate exercise. For that, I generated a new div with the id "questionLoad", and set its content to the given exercise. I tried to render it with mathjax with MathJax.Hub.Queue(['Typeset',MathJax.Hub,"loadQuestion"]); but then I got the following Error:

enter image description here

Here is the relevant function:

function startGame() {
    console.log("starting the game");
    let spinner = `
        <div class="spinner-border text-primary" role="status">
  <span class="visually-hidden">Loading...</span>
</div>
`
    // adding a loading animation until the server responds
    $("#wrapper").html("<h3>Loading .... </h2>" + spinner); 
    
    let requestDict = { // telling the server to fetch a linear equation
        type: 'LinEq',
    };
    const requestJson = JSON.stringify(requestDict);
    fetch(`the server path`)
        .then(function(response) {
            return response.text();
        }).then(function(server_response) { 
            // change the text of the div from a loading to the loaded equation
            $("#wrapper").html(`<div id='loadQuestion'><span style='font-size:25px;'>${server_response}
                   </span></div>`);
            // load MathJax into the div. Doesn't work!
            MathJax.Hub.Queue(['Typeset', MathJax.Hub, "loadQuestion"]);
            
        });
}

I would really appreciate any suggestions. Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You have to supply the DOM element as the third argument, not the id of the DOM element.

MathJax version 2

MathJax.Hub.Queue([
    'Typeset', 
    MathJax.Hub, 
    $("#loadQuestion")[0]
])

Working sandbox sample: https://codesandbox.io/s/so-71615834-mj2-9w4b9f

MathJax version 3

MathJax.startup.promise.then(() => {
    MathJax.typesetClear([$("#holder")[0]]);
    MathJax.typeset([$("#holder")[0]]);
})

Working sandbox sample: https://codesandbox.io/s/so-71615834-mj3-yx1d41

In both versions, if you leave out the element to typeset, the whole page will be typeset anew.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda