/    Sign up×
Community /Pin to ProfileBookmark

Replacing Text Content for Special Characters

I’m a pretty experienced developer, but this problem is driving me bonkers. I’m trying to use the onclick event to change the HTML up arrow special character to a down arrow when clicked, and vice versa ( i.e. &uarr; <–> &darr; ). Here’s what I’m currently doing:

[CODE]
<script type=”text/javascript”>
//<![CDATA[
if(document.all) {
if (document.getElementById(‘FundedSortArrow’).innerText == ‘&uarr;’) {
document.getElementById(‘FundedSortArrow’).innerText = ‘&darr;’;
}
else {
document.getElementById(‘FundedSortArrow’).innerText = ‘&uarr;’;
}
}
else {
if (document.getElementById(‘FundedSortArrow’).textContent == ‘&uarr;’) {
document.getElementById(‘FundedSortArrow’).textContent = ‘&darr;’;
}
else {
document.getElementById(‘FundedSortArrow’).textContent = ‘&uarr;’;
}
}
//]]>
</script>
[/CODE]

What happens is that the special characters are taken literally, so &uarr; and &darr; are printed to the screen instead of what they are intended to represent.

I understand I could be using the tertiary operator, etc., to make everything more elegant, but that’s not what I’m after here.

Thanks for any help that you can provide.

bubbis

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@mrhooJan 13.2009 — var el= document.getElementById('FundedSortArrow');

var ccode= el.innerHTML.charCodeAt(0);

if(ccode==8595) el.innerHTML= '&uarr;';

else if(ccode==8593) el.innerHTML= '&darr;';
Copy linkTweet thisAlerts:
@bubbisthedogauthorJan 13.2009 — var el= document.getElementById('FundedSortArrow');

var ccode= el.innerHTML.charCodeAt(0);

if(ccode==8595) el.innerHTML= '&uarr;';

else if(ccode==8593) el.innerHTML= '&darr;';[/QUOTE]


Worked perfectly (it would've taken me a good bit of time to figure that out). Thanks a lot for taking the time to help me, hoo.

Regards,

bubbis
×

Success!

Help @bubbisthedog spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...