If you want to keep the tags unread, you can replace <
and >
with your HTML entity <
and >
respectively. The result the browser will interpret as a common text:
var msg = $('input').val();
msg = msg.replace(/</g, '<').replace(/>/g, '>');
$("body").append(msg);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputvalue="<b>abc</b>">
Removing tags with .replace
and regular expression
var msg = $('input').val();
msg = msg.replace(/<.+?>/g, '');
console.log(msg)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputvalue="<i class='classe'>abc1</i> <b>def2</b>">
The expression <.+?>
captures everything that is <nome da tag, atributos, fechamento etc.>
and .replace
removes the string.