문제

¿Has anybody tried to access the "mtext" elements generated by MathJax.js library from jquery?

I have something like this:

<mrow>
   <mo>(</mo>
       <mtext>Producción‌·de‌·naranjas&nbsp;&nbsp;</mtext>
   <mo>)</mo>
</mrow>

but i cant select any mtext element. I tried using $('mtext').addClass('red') but it didnt work.

Thanks

도움이 되었습니까?

해결책 2

It works for me using the same code as you: $('mtext').addClass('red');.

Perhaps you are not waiting until the markup has actually been loaded/added to the DOM before running the jQuery selector? That would prevent jQuery from finding any elements to add the class to.

다른 팁

MathJax removes the MathML elements and replaces them with HTML elements to perform the layout in most browsers. So there are no mtext elements after that. The HTML-CSS output jax does retain the structure of the MathML and marks the spans that it creates with classes that correspond to the original nodes. So try

$('.mtext').addClass('red');

though it might just be easier to add

.mtext { color: red }

to your CSS rather than using jQuery to add it later, unless you need to change it dynamically.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top