# How to add a fraction through javascript?

How to add a fraction through javascript?

I am making a custom explanation of how to solve some math problems, and it requires manually adding latex through javascript. For example:
HTML:
<div id='printContainer'></div>
JS:

var x = 5; var y = 4; document.getElementById('parseContainer').innerHTML = '\frac{' + x + '+_2' +y + '_2}{2}';The result will look like this: http://i.imgur.com/nvq5yma.png Is it possible to directly add latex through js? Thanks.

8 Dec 14, 3:33PM

Thank you for responding very quickly to my question. What do you mean by escaping my quotes? I understand what that means, but I don't understand how it applies here. Can you show me an example? Sorry.

24 May 15, 4:50AM

I suspect you need to escape your '\' in \frac. i.e.

document.getElementById('parseContainer').innerHTML = '\\frac{' + x + '+_2' +y + '_2}{2}'