Skip to main content
added 247 characters in body
Source Link

Indeed $ is jQuery, the extra library you need to load

But..[drumroll] Microsoft has mQuery... so you do not need jQuery

var headline = m$(ctx.CurrentItem.Body)[0].textContent;

Or in native (modern browser) JavaScript:

var headline = document.querySelector(ctx.CurrentItem.Body).textContent;

But... chicken/egg

It won't work because the DOM element you want to get the text from does not exist (because this CSR code creates it)

The text you want is in the items ctx object:

If you call it for the whole Item:

var headline = ctx.CurrentItem.Body; 

The above is tied to the Internal name;

If you call it for (any) one Description Column as shown in the MSDN example that internal name is declared in the ctx object:
and creates more generic/reusable code

var headline = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; 

FYI: This type of CSR development is a breeze with the free Chrome Browser Cisar Plugin

Indeed $ is jQuery, the extra library you need to load

But..[drumroll] Microsoft has mQuery... so you do not need jQuery

var headline = m$(ctx.CurrentItem.Body)[0].textContent;

Or in native (modern browser) JavaScript:

var headline = document.querySelector(ctx.CurrentItem.Body).textContent;

But... chicken/egg

It won't work because the DOM element you want to get the text from does not exist (because this CSR code creates it)

The text you want is in the items ctx object:

var headline = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; 

FYI: This type of CSR development is a breeze with the free Chrome Browser Cisar Plugin

Indeed $ is jQuery, the extra library you need to load

But..[drumroll] Microsoft has mQuery... so you do not need jQuery

var headline = m$(ctx.CurrentItem.Body)[0].textContent;

Or in native (modern browser) JavaScript:

var headline = document.querySelector(ctx.CurrentItem.Body).textContent;

But... chicken/egg

It won't work because the DOM element you want to get the text from does not exist (because this CSR code creates it)

The text you want is in the items ctx object:

If you call it for the whole Item:

var headline = ctx.CurrentItem.Body; 

The above is tied to the Internal name;

If you call it for (any) one Description Column as shown in the MSDN example that internal name is declared in the ctx object:
and creates more generic/reusable code

var headline = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; 

FYI: This type of CSR development is a breeze with the free Chrome Browser Cisar Plugin

Source Link

Indeed $ is jQuery, the extra library you need to load

But..[drumroll] Microsoft has mQuery... so you do not need jQuery

var headline = m$(ctx.CurrentItem.Body)[0].textContent;

Or in native (modern browser) JavaScript:

var headline = document.querySelector(ctx.CurrentItem.Body).textContent;

But... chicken/egg

It won't work because the DOM element you want to get the text from does not exist (because this CSR code creates it)

The text you want is in the items ctx object:

var headline = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; 

FYI: This type of CSR development is a breeze with the free Chrome Browser Cisar Plugin