最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - special characters in title tag - Stack Overflow

programmeradmin2浏览0评论

How do you enter special characters in the title attribute of html?

My JavaScript code:

var link_english = document.createElement("img");
   link_english.setAttribute("src", "images/english_out.png");
   link_english.setAttribute("title", "The english version of Nauma"); // 
   link_english.className = "classEnglish";

My question is: How do I insert a special tag within the value of the title attribute?

Example:

link_english.setAttribute("title", "here I want to put a special character for a German letter, the " ü " ");

If it is a normal html file, no problem.

How do you enter special characters in the title attribute of html?

My JavaScript code:

var link_english = document.createElement("img");
   link_english.setAttribute("src", "images/english_out.png");
   link_english.setAttribute("title", "The english version of Nauma."); // 
   link_english.className = "classEnglish";

My question is: How do I insert a special tag within the value of the title attribute?

Example:

link_english.setAttribute("title", "here I want to put a special character for a German letter, the " ü " ");

If it is a normal html file, no problem.

Share Improve this question edited Feb 4, 2019 at 19:30 SherylHohman 18k18 gold badges93 silver badges96 bronze badges asked Apr 10, 2011 at 11:04 dimadima 311 gold badge1 silver badge3 bronze badges 2
  • What special characters? – BoltClock Commented Apr 10, 2011 at 11:06
  • In what context? I don't understand. Please add more detail. – Pekka Commented Apr 10, 2011 at 11:07
Add a ment  | 

2 Answers 2

Reset to default 4

Just enter them.

You only need to ensure that the HTML page is saved using a character encoding which supports those characters (UTF-8 is preferred if you want world domination) and that the HTML page is been served over HTTP with a Content-Type header which signifies the very same character encoding, so that the browser understands how to display them to the human, e.g text/html;charset=UTF-8.

How to save the files the right way depends on the editor used, but usually this is available by Save As function and/or in the general editor settings. How to set the right HTTP content type header depends on the programming language and/or webserver used.


Update: the above answer still applies on your update. Save/serve file as UTF-8 and instruct browser by Content-Type header to interpret it as UTF-8. This applies on JS files as good as on HTML files and other text based files.

Yes you can but to enter special character you have to use its HTML entity. Here is the table for special characters and its HTML entity.

发布评论

评论列表(0)

  1. 暂无评论