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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
David S.Connect With a Mentor 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
 
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
 
leakim971Connect With a Mentor PluritechnicianCommented:
Ok, new one : http://fiddle.jshell.net/kHnPa/1/show/

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

Open in new window

0
All Courses

From novice to tech pro — start learning today.