Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

2 of 3
insert duplicate link

javascript: alt attribute with special characters

Possible Duplicate:
Alt attribute encoding with JavaScript

I can't seem to assign special characters using javascript in alt tags and have them render in any browser.

Without javascript, special characters in alt tags render fine (PepsiTM):

<img id="pic" src="path/to/image.jpg" alt="Pepsi&trade;" />

However, when assigning this same value via javascript or jquery you get (Coke&trade;).

$("#pic").attr("alt","Coke&trade;") or image = document.getElementById('pic'); image.alt="Pepsi&trade;"

This issue exists in chrome and IE6; I haven't tried other browsers. Any ideas?

lang-js

AltStyle によって変換されたページ (->オリジナル) /