1

I have a series of quotes that look like this:

<p>Being a graphic designer gets you used to rejection of your brilliance. So it&#8217;s good practice for dating. </p> 

I would like them to look like this:

 Being a graphic designer gets you used to rejection of your brilliance. So it's good practice for dating. 

I tried using innerHTML, with limited success.

2
  • innerhtml fetches the html, obviously. try innerText Commented Jul 15, 2016 at 17:17
  • "I would like them to look like this" Not certain what you are trying to achieve? The first example should render ' as text appears to be enclosed in <p> element? Commented Jul 15, 2016 at 17:19

1 Answer 1

3

Create a temporary span element with the html content as string using document.createElement method. Later get the text content by getting the textContent property.

var str = '<p>Being a graphic designer gets you used to rejection of your brilliance. So it&#8217;s good practice for dating. </p>'; // create a span element var temp = document.createElement('span'); // set the html to the element temp.innerHTML = str; // get the text content console.log(temp.textContent);

Sign up to request clarification or add additional context in comments.

1 Comment

I tried it on a JSON string, it does not work... it returns undefined

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.