JavaScript: Entity in document.title

How can I add a dash to my document.title using JavaScript?
<script type="text/javascript">
 document.title='Hello &#8212; World';
</script>

Open in new window

LVL 16
hankknightAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Which browser version?
Work for me : http://fiddle.jshell.net/kHnPa/show/
document.title = "Hello - World"

Open in new window

0
hankknightAuthor Commented:
Thanks, but my question is about how to get a numbered entity into the title.

"—" is NOT the same a "-", it is much wider.  I want to define it with the entity number, &#8212;
0
leakim971PluritechnicianCommented:
Ok, new one : http://fiddle.jshell.net/kHnPa/1/show/

document.head.getElementsByTagName("title")[0].innerHTML = "Hello &#8212; World";

Open in new window

0
David S.Commented:
Special characters are written differently in JavaScript than they are in HTML. More info: https://developer.mozilla.org/en/JavaScript/Guide/Values,_Variables,_and_Literals#Unicode_Escape_Sequences

You convert the number to hexadecimal (assuming you're using a decimal character entity) and prefix it with "\u", like this:
document.title='Hello \u2014 World';

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.