In this SharePoint tutorial, we will discuss how to remove sharepoint multiple lines of text HTML tags.
In my project, I need to show the address in a text area from the multiline text field while the user wants to edit the address. But while I was reading the description I see HTML tags in the text as shown below. I have implemented this code in ECMA scripting.
I was trying to get the car description, as a normal since a line of text field. So it is getting all the HTML tags also in it.
Var aboutcar = objListItem.get_item('AboutCar');
Note: The code block was implemented in ECMA scripting.
Remove DIV tag from Multiline text field using ECMA in SharePoint
Below are different ways we can remove the div tags from the multiline text field using ECMA script in SharePoint Online/2013/2016.
I should remove the div tags from the text with any of below procedures:
- Apply Regular expression
- Use jQuery
- Creating a temporary DOM element
Let us walk through one by one.
Remove DIV tag from Multiline text field by Apply Regular expression
As we know regular expressions help us to replace or remove the test from a string. The below syntax helps us to remove the div tag from the description.
var aboutcar = objListItem.get_item('AboutCar').replace(/[^>]+>/g,'');
The above code will remove all the HTML tags recursively as I used /g.
Remove DIV tag from Multiline text field using jQuery
If you are using jQuery you can use the below code snippet.
var aboutcar = objListItem.get_item('AboutCar');
var abtCarVal = $("<div>").html(aboutcar).text();
Remove DIV tag from Multiline text field by creating a temporary DOM element
This approach involves creating a temporary DOM element with the type DIV. The below code sample explains how we can achieve the HTML tag-free text from Multiline Text fields.
alert(fnRemoveDIVTag(objListItem.get_item('AboutCar'));
Function fnRemoveDIVTag(strDescription)
{
// Create a new div element
var tmpDivElmnt = document.createElement("div");
// Set the HTML content with the providen
tmpDivElmnt.innerHTML = strDescription;
// Retrieve the text property of the element (cross-browser support)
return tmpDivElmnt.textContent || tmpDivElmnt.innerText || "";
}
The output for all the approaches will be:
You may like following SharePoint tutorials:
- Get SharePoint 2013 List Item Count using Rest API and ECMAScript object model
- Read, create, update, delete a file using JavaScript object model (jsom) in SharePoint
- Get Current User Details Using JavaScript Object Model (jsom) and jQuery in SharePoint 2013/2016/Online
- Uncaught TypeError: Cannot read property get_current of undefined error SharePoint Online jsom
- User profile synchronization service stuck on starting SharePoint 2013/2016
- Download files from SharePoint document library using PowerShell
- Display SharePoint List items in a data table using Rest API and jQuery
In this SharePoint tutorial, we discuss various approaches to remove Remove DIV tag from Multiline text field in ECMA script in SharePoint Online or SharePoint 2013/2016.
I am Krishna.Vandanapu a SharePoint architect working in IT from last 13+ years, I worked in SharePoint 2007, 2010, 2013, 2016 and Office 365. I have extensive hands on experience in customizing SharePoint sites from end to end. Expertise in SharePoint migration tools like Sharegate, Doc Ave and Metalogix. Migrated SharePoint sites from SharePoint 2007 to 2010 and 2010 to 2013 several times seamlessly. Implementing CSOM with Microsoft best practices. Spent quality time in configuring SharePoint application services like User Profile, Search, Managed Meta data services etc. Now exploring SharePoint Framework and SharePoint 2019