Posts tagged with HTML

HTML and XML Character Encoding Gotchas in Javascript

December 8th, 2009

Recently I was trying to execute the following Javascript with jQuery: $("#someid").append("<div>...&deg;C</div>");

I was going crazy because it worked (a degrees symbol – ° – was shown) on one page but not another, where nothing was displayed or returned by the append method. After much frustration I stumbled on a solution and I’m sharing it here to hopefully save others some time.

I was stumped but luckily I ended up reading the Wikipedia page on character encoding in HTML and learned that XML has a much smaller set of character entity references. In fact, there are only five: &amp; → &, &lt; → <, &gt; → >, &quot; → “, &apos; → ‘. Makes sense, since you should be using UTF-8.

As it turns out, my working example was an HTML page while the non-working one was XHTML. Because of the XHTML content-type declaration the parser (I’m not sure whether in jQuery or my browser) was choking on the invalid character entity reference and failing completely. So, problem solved, though I wish the single offending entity was dropped, not the whole string!

Vodafone Mobile Widget Camp

April 21st, 2009

I’m one of the organizers of the Mobile Widget Camp on May 2. The free event is taking place at Pakhuis de Zwijger, Amsterdam. Daniel Appelquist (Vodafone Betavine), Peter-Paul Koch (Quirksmode), and Elliot Kember (Carsonified) are among the speakers in the morning, so you’re guaranteed to get a great introduction to Vodafone/Opera widgets. Beside these speakers there will be hands-on workshops and time to code your own mobile widgets. Anyone with basic HTML, CSS and Javascript knowledge can make a mobile widget, so make sure to come and help will be available from experts to help you coding. Read more about Mobile Widget Camp on the website.