The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> string.replace against html symbol code (&divide)?
CharliePrince
post Jan 9 2021, 03:38 AM
Post #1


Novice
**

Group: Members
Posts: 24
Joined: 7-November 20
From: Saint Louis, MO
Member No.: 27,623



I'm trying to replace an html symbol code '&divide' with another string.

I can't get this to work. See example below.

CODE
     <body>

         <p id='target'>A &divide B</p>
         <script>
             console.log(`${document.getElementById('target').innerText}`);

             console.log(`${document.getElementById('target').innerText.replaceAll('รท', '/')}  (want this to = 'A / B') `);

             console.log(`${document.getElementById('target').innerText.replaceAll('&divide', '/')}  (or, want this to = 'A / B') `);

         </script>

     </body>



Can anyone help? Pandy?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
CharliePrince   string.replace against html symbol code (&divide)?   Jan 9 2021, 03:38 AM
pandy   I don't follow your console.log examples. But ...   Jan 9 2021, 04:28 AM
Christian J   It seems innerHTML returns the actual character, ...   Jan 9 2021, 09:18 AM
pandy   I saw that thread, but not that Korpola was there....   Jan 9 2021, 09:24 AM
pandy   It's worse. Look at this. <p id='targe...   Jan 9 2021, 09:29 AM
Christian J   Even worse: <p onclick="alert(this.i...   Jan 9 2021, 02:34 PM
pandy   You tell me! :wacko:   Jan 9 2021, 02:37 PM
pandy   You tell me! :wacko: And look at this...   Jan 9 2021, 02:42 PM
pandy   That was k-mel. Edge, IE and FF do the same thing....   Jan 9 2021, 02:52 PM
Christian J   Could it have something to do with ASCII or Unicod...   Jan 9 2021, 02:56 PM
pandy   But for example &larr; has been around as long...   Jan 9 2021, 02:58 PM
pandy   The whole first column form here https://htmlhelp....   Jan 9 2021, 03:06 PM
pandy   Among these I found two more that aren't inter...   Jan 9 2021, 03:23 PM
CharliePrince   Pandy, your example seems to work here ha. Also,...   Jan 9 2021, 04:07 PM
CharliePrince   I didn't notice your most recent posts here un...   Jan 9 2021, 04:26 PM
Christian J   I don't know the words to describe but I thin...   Jan 9 2021, 08:47 PM
pandy   :shades: :shades: :shades: :shades: :shades: ...   Jan 10 2021, 04:25 AM
pandy   I demand to get a gold star after my name! :s...   Jan 10 2021, 05:04 AM
pandy   If the entity is one of the not 'interpreted...   Jan 10 2021, 05:11 AM
pandy   Still want my gold star. :angry2:   Jan 10 2021, 05:12 AM
Christian J   Still want my gold star. :angry2: You can have...   Jan 10 2021, 03:19 PM
Christian J   :shades: :shades: :shades: :shades: :shades: ...   Jan 10 2021, 03:18 PM
pandy   Strange, this does not work: [code]<p id=...   Jan 10 2021, 03:30 PM
Christian J   I was googling html entities and javascript and s...   Jan 10 2021, 04:16 PM
pandy   Nope. I didn't know about this and I hadn...   Jan 10 2021, 04:46 PM
Christian J   CSS generated content? Maybe I saw that page when ...   Jan 10 2021, 07:56 PM
pandy   Haven't seen that page either. The only things...   Jan 10 2021, 08:10 PM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 25th May 2024 - 06:39 AM