Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove HTML tags from a javascript string

I have this code :

var content = "<p>Dear sms,</p><p>This is a test notification for push message from center II.</p>"; 

and I want to remove all <p> and </p> tags from the above string. Just want to display the string values without html tags like :

"Dear sms, This is a test notification for push message from center II." 
like image 457
krrr25 Avatar asked Dec 17 '12 09:12

krrr25


People also ask

Can JavaScript remove HTML?

Given an HTML element and the task is to remove the HTML element from the document using JavaScript. Approach: Select the HTML element which need to remove. Use JavaScript remove() and removeChild() method to remove the element from the HTML document.

How do I remove a tag from a string?

The HTML tags can be removed from a given string by using replaceAll() method of String class. We can remove the HTML tags from a given string by using a regular expression. After removing the HTML tags from a string, it will return a string as normal text.

Is it possible to remove the HTML tags from data?

Strip_tags() is a function that allows you to strip out all HTML and PHP tags from a given string (parameter one), however you can also use parameter two to specify a list of HTML tags you want.

How remove HTML tag from string in react?

To remove html tags from string in react js, just use the /(<([^>]+)>)/ig regex with replace() method it will remove tags with their attribute and return new string.


1 Answers

Why not just let jQuery do it?

var content = "<p>Dear sms,</p><p>This is a test notification for push message from center II.</p>";  var text = $(content).text(); 
like image 107
Blender Avatar answered Oct 02 '22 03:10

Blender