Nishant Kumar
Nishant Kumar

Reputation: 6103

How to replace a Character in text By jquery

How to replace a charcter within a text For instance

 <script>alert("Hi i am nishant");</script>

here i want to replace < and > by ASCII code so how i will replace it.

Upvotes: 5

Views: 1308

Answers (1)

thejh
thejh

Reputation: 45578

var text = text.replace(/</g, "&lt;").replace(/>/g, "&gt;");

Upvotes: 6

Related Questions