HTML entities like ' are decoded by the browser BEFORE Alpine evaluates the expression, so the JS parser still sees a raw single quote. Backslash escape (\') is the correct approach: the HTML parser preserves it, then JavaScript interprets \' as an escaped quote in the string literal.