Alexandru Vlas
Alexandru Vlas

Reputation: 1415

Single quotes inside single quotes cause error

I have this code:

<span onmouseout="tooltip.hide();" onmouseover="tooltip.show('Hello. This is a simple tooltip, I'm here if you need me, we've been away for some time.');" class="hotspot">test link</span>

the thing is that the SINGLE quote ' is causing the tooltip not to show... so I mean IF the text contains ' the tooltip will not show... because all the text is already inside single quotes...

Can someone please help me to fix this?

Upvotes: 0

Views: 369

Answers (3)

prog1011
prog1011

Reputation: 3495

Use &rsquo; for Special Characters in HTML.

<span onmouseout="tooltip.hide();" onmouseover="tooltip.show('Hello. This is a simple tooltip, I&rsquo;m here if you need me, we&rsquo;ve been away for some time.');" class="hotspot">test link</span>

I created Working Demo with alert() you can run this code snippet :)

<span onmouseover="alert('Hello. This is a simple tooltip, I&rsquo;m here if you need me, we&rsquo;ve been away for some time.');"
class="hotspot">test link</span>

Upvotes: 0

Alexandru Vlas
Alexandru Vlas

Reputation: 1415

Fixed this myself.

So I just replaced every instance of ' to \' in str_replace function :)

WAS:

$desc = str_replace('"', "",  preg_replace('/(\s\s+|\t|\n)/', ' ', JFilterOutput::cleanText($regs[0]))); 

IS NOW:

$desc = str_replace("'", "\\'",  preg_replace('/(\s\s+|\t|\n)/', ' ', JFilterOutput::cleanText($regs[0]))); 

Upvotes: 0

Ben Yee
Ben Yee

Reputation: 1585

Try setting the tooltip text to a var and then doing a replace on the single quote with &apos;

var tooltip = tooltip.replace(/'/g, "&apos;");

Upvotes: 1

Related Questions