I'm trying to display a rich text field but all I get is something like this:

enter image description here

Here is the code I'm using:

var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
  //Use for Cross Site Data
   var siteUrl = /sites/MySPSite/CurSite;

    //clientContext = new SP.ClientContext.get_current();
    clientContext = new SP.ClientContext(siteUrl);
    web = clientContext.get_web();
    var list = web.get_lists().getByTitle("Posts");
    var camlQuery = new SP.CamlQuery();
    var q = "<View><Query><OrderBy><FieldRef Name='PublishedDate' Ascending='False'/></OrderBy></Query><RowLimit>1</RowLimit></View>";
    this.listItems = list.getItems(camlQuery);
    clientContext.load(listItems, 'Include(Id, Title, Body, Blurb)');
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess), 
    Function.createDelegate(this, this.onQueryFailed));
function onListItemsLoadSuccess(sender, args) {
   var listItemEnumerator = this.listItems.getEnumerator();
   while (listItemEnumerator.moveNext()) {
        var item = listItemEnumerator.get_current();
var itemId = item.get_id();
var curTitle = item.get_item('Title');
          var curBody = item.get_item('Body');



function onQueryFailed(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());

What should I be using to get the Rich Text content to display properly?

  • 1
    try changing $('#postBody').text(curBody); to $('#postBody').html(curBody); Jul 27, 2016 at 19:41

1 Answer 1


Everything looks like it is working properly in your code, you are getting the data and manipulating the DOM. So that leaves why are you are seeing the results you are. That is because you are doing $('#postBody').text(curBody); instead of $('#postBody').html(curBody);.

This is taking your data and making it raw text. Use the .html to make it literal html and you should get the result you are looking for.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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