May 20, 2019

How to get content from lightning:inputRichText without HTML Tags?

Sample Code:

Lightning Component:


  1. <aura:component implements = "force:appHostable">  
  2.       
  3.     <aura:attribute name="myVal" type="String" />  
  4.       
  5.     <div class="slds-box slds-theme_default">  
  6.           
  7.         <lightning:inputRichText value = "{!v.myVal}"/>  
  8.         <lightning:button variant = "brand" label = "Show" onclick = "{! c.handleClick }"/>  
  9.           
  10.     </div>  
  11.       
  12. </aura:component>  

Lightning Component Controller:


  1. ({  
  2.       
  3.     handleClick : function(component, event, helper) {  
  4.           
  5.         var tempVal = component.get("v.myVal");  
  6.         var tempDivElement = document.createElement("div");  
  7.         tempDivElement.innerHTML = tempVal;  
  8.         alert( "With HTML Tags " + tempVal );  
  9.         tempVal = tempDivElement.textContent;  
  10.         alert( "Without HTML Tags " + tempVal );  
  11.           
  12.     }  
  13.       
  14. })  

Output:






No comments:

Post a Comment