By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

Issues with HTML entity references and Javascript?

P: 20
I'm having trouble displaying entity references (i.e. >, <, etc). I'll show the code first, then ask my question. This code makes sub items on a menu appear or disappear. The HTML isn't giving me issues, so I'm only posting the javascript for now:

Javascript code:

Expand|Select|Wrap|Line Numbers
  1. function expandcollapseBGrows(anchor) {
  2. var span = document.getElementById("BGrows");
  3. span.style.display = (span.style.display=='block')?'none':'block';
  4. anchor.innerHTML = (anchor.innerHTML=='hide')?'&raquo;':'hide';
  5. }
  6.  

Now, here's my question. This code currently works - when I click on the hide link, my subitems are hidden and I see a right angle quote. When I click on the right angle quote, my subitems appear, and my link changes to "hide."

If I replace "hide" with "&laquo;" in the script, though, I run into a problem. Everything still appears and disappears as it should. However, my link, instead of changing from a right angle quote to a left angle quote, now just changes to a left angle quote, and then stays that way. It doesn't change back to a right angle quote.

This seems strange, since it switches back and forth without problems if it is text. For some reason, though, entity references seem to throw it off.
Oct 9 '07 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
I'm not sure, but it might be converting it to Ascii or something. You may need to look at charCodeAt and parse the string.
Oct 10 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.