[Solved] How to assign a string to a variable in javascript when the string has a single quote in it

[ad_1]

Replace single quote (escape it like PHP):

<script>
    var quotes = "Empty"
        if(user.quotes)
           quotes = user.quotes.replace(/'/g,"\\\'");    // get the string to 'quotes' variable
</script>

Then wherever You use Your quotes, replace the “\'” back to “‘”.

0

[ad_2]

solved How to assign a string to a variable in javascript when the string has a single quote in it