How to escape double quotes in a title attribute
I am trying to use a string that contains double quotes in the title attribute of an anchor. So far I tried these:
<a href=".." title="Some \"text\"">Some text</a>
<!-- The title looks like `Some \` --!>
and
<a href=".." title="Some "text"">Some text</a>
<!-- The title looks like `Some ` --!>
Please note that using single quotes is not an option.
Solution 1:
This variant -
<a title="Some "text"">Hover me</a>
Is correct and it works as expected - you see normal quotes in rendered page.
Solution 2:
Here's a snippet of the HTML escape characters taken from a cached page on archive.org:
< | < less than sign
@ | @ at sign
] | ] right bracket
{ | { left curly brace
} | } right curly brace
… | … ellipsis
‡ | ‡ double dagger
’ | ’ right single quote
” | ” right double quote
– | – short dash
™ | ™ trademark
¢ | ¢ cent sign
¥ | ¥ yen sign
© | © copyright sign
¬ | ¬ logical not sign
° | ° degree sign
² | ² superscript 2
¹ | ¹ superscript 1
¼ | ¼ fraction 1/4
¾ | ¾ fraction 3/4
÷ | ÷ division sign
” | ” right double quote
> | > greater than sign
[ | [ left bracket
` | ` back apostrophe
| | | vertical bar
~ | ~ tilde
† | † dagger
‘ | ‘ left single quote
“ | “ left double quote
• | • bullet
— | — longer dash
¡ | ¡ inverted exclamation point
£ | £ pound sign
¦ | ¦ broken vertical bar
« | « double left than sign
® | ® registered trademark sign
± | ± plus or minus sign
³ | ³ superscript 3
» | » double greater-than sign
½ | ½ fraction 1/2
¿ | ¿ inverted question mark
“ | “ left double quote
— | — dash
Solution 3:
The escape code "
can also be used instead of "
.