Escaping apostrophes in a string stored in a variable

Twine Version: 2.10.0
Sugarcube 2.37.3

I’m creating a hover effect using this technique:

<<set $playerName to "Megan's">>

<a @onmouseover="'$(\'.hover-content\').text(\'It is '+$playerName+' turn\')'" data-passage="Page 2">Hover Over Me</a>

<div class="hover-content"></div>

The problem is this gives an error because of the apostrophe in “Megan’s”. Any way to get around this? It works fine without the apostrophe.

I think at this point it would be easier to use a custom macro. You can paste this into your javascript section, then do something like this:

<<set $playerName to "Megan's">>

<<mouseover>>
    <<link 'Hover Over Me'>><</link>>
<<onmousein>>
    <<replace '.hover-content'>>It is $playerName turn.<</replace>>
<<onmouseout>>
    <<replace '.hover-content'>><</replace>>
<</mouseover>>

<div class="hover-content"></div>

Perfect. Thank you!