Android WebView getElementById ('math') not working dynamically

I have one WebViewin that I downloaded MathJax.js using the following code.

webView.loadDataWithBaseURL("","<script type='text/javascript' "
                  + "src="+ url +"></script>"
                  + "<span id='math'></span>"
                  /** 
                    I want set text dynamically for above span tag
                    using following script.
                   **/
                  + "<script type='text/javascript'>"
                  + "document.getElementById(\"math\").innerHTML='\\\\["+doubleEscapeTeX(question.getQuestion())+"\\\\]';"
                  + "</script>","text/html","utf-8","");

I want dynamic text to be listed above the tag <span>using the following <script>.

<script type='text/javascript'>
   document.getElementById(\"math\").innerHTML='\\\\"+doubleEscapeTeX(question.getQuestion())+"\\\\]';"
</script>

How can I install using again WebView?

In short, I want to load javascript only once, and other content is loaded dynamically every time.

Your help will be appreciated.

+4
source share
1 answer

Try using

"$(function() { ... });" 

or

 "$(document).ready(function() { ... });".

<script type='text/javascript'>
   $(document).ready(function() {
    document.getElementById(\"math\").innerHTML='\\\\"+doubleEscapeTeX(question.getQuestion())+"\\\\]';"
   });
</script>
0
source

All Articles