Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 554
Nishant Kumar Avatar asked Nov 25 '10 14:11

Nishant Kumar


People also ask

How can I replace all characters in a string using jQuery?

The replaceAll() method is an inbuilt method in jQuery which is used to replace selected elements with new HTML elements. Parameters: This method accepts two parameter as mentioned above and described below: content: It is the required parameter which is used to specify the content to insert.

How do I replace a character in a string?

The Java String class replace() method returns a string replacing all the old char or CharSequence to new char or CharSequence.

How do I remove a character from a string in jQuery?

text(). replace('-', ''); jquery.

How do you replace an element with another in jQuery?

We can replace HTML elements using the jQuery . replaceWith() method. With the jQuery replaceWith() method, we can replace each element in the set of matched elements with the provided new content and return the set of elements that were removed.


1 Answers

var text = text.replace(/</g, "&lt;").replace(/>/g, "&gt;");
like image 144
thejh Avatar answered Sep 21 '22 03:09

thejh