Is there an easy way to convert text into HTML in JavaScript?

html, javascript, jquery

Solution

If you want to use jQuery, you can use the `text(string)` method.

$(".selector").text("x < 5");

http://api.jquery.com/text/

Problem

Possible Duplicate: Escaping HTML strings with jQuery JavaScript/jQuery HTML Encoding For example, if I wanted to show the user the string `x < 3` in HTML I would need to replace the `<` character with `&lt;`. Is there a prebuilt function to do this in JavaScript or perhaps jQuery that converts any text string into the corresponding HTML?

Original source

Related problems