I’m trying to strip HTML tags from a string following this post. The string I’m trying to strip the tags from is a JSON property named item.content. So my code looks like this:
$(item.content).text();
If the value of item.content is the following it works great:
El mexicano Marco Rodríguez será el árbitro del duelo entre Corinthians y Al Ahly
If however, item.content is this, I get an error:
‘Prefiero ganar la Décima, aunque el Barça nos saque 25 puntos’, dice Iker Casillas
The error is Error: Syntax error, unrecognized expression. I’m guessing this is because of the single quotes, but I’m not sure how to fix it. Any advice?
If you want to use the .text()(or any other jQuery) function on that string, you need to add it to an element so you can use any jQuery methods on it. Ex.
Or using a valid string with elements
as @Kevin B noted in the comments..
Using
is correct way for this example because you want to preserve the html