I'm building a web application and experiencing a weird issue. I have a Sitecore RTF containing some formatted text and a link In my web application I have an HTML file with the following snippet:

<div class="AudiologiInfoText">

and in my javascript file I have:

var x = $('.AudiologiInfoText')
if (x.length > 0) {

Running it on my machine, x[0] returns a div containing a string containing the text formatted with HTML tags When I run it on our test server, instead of being inside a string, the div directly contains the HTML tags.

This results in the innerText() call to lose the formatting on the test server.

The test server has a separate Sitecore client but I've input the exact same text in the same manner. I don't understand how it can be returning different results?

  • Could you please make sure you are not missing any closing tag? try to change the RTE field value in raw value and then compare it. – Mahendra Shekhawat Apr 7 at 14:49
  • You say you have 2 different Sitecore clients. If you go into the RTE and go into the HTML view (you can switch using the button on the bottom left), do they have differences? – Trayek Apr 7 at 15:47
  • I have checked both the raw value and the HTML view, they are completely identical. – svantis Apr 8 at 6:55
  1. Make sure the environments are synchronized - the files, js, rich text in Sitecore.
  2. Compare the view-source for the two pages to help find the discrepancy
  3. Try using innerHTML instead of innerText
  4. Consider refactoring this - use @Html.Sitecore().Field("AudiologiInfoBox") inside the InfoBoxText div instead of using jQuery.
  • 1. From what I can tell the environments are synchronized. 2. Viewing the source I actually found a discrepancy. On my machine, the HTML tags are represented as e.g. &lt;p&gt for a p tag. On the test server, they are represented as <p>. This is the only difference I can find. 3. InnerHTML makes it work on the test server but not on my machine as it then displays the tags as part of the text on my machine 4. The InfoBoxText div is sadly created from a js file and from what I've been told you can't access Sitecore fields from js – svantis Apr 8 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.