Removing #HTML tags from a string via #Javascript #jQuery

0 Shares
0
0
0
0
0
0
0

We can remove HTML/XML tags in a string using regular expressions in javascript. HTML elements such as span, div etc. are present between left and right arrows for instance, etc. So replacing the content within the arrows, along with the arrows, with nothing(”) can make our task easy.

<html>
<body>
<script>
function removeTags(binarystring) {
   if ((binarystring===null) || (binarystring===''))
   return false;
else
binarystring = binarystring.toString();
return binarystring.replace( /(<([^>]+)>)/ig, '');
}
document.write(removeTags('<html> <body> Javascript<body> is not Java'));;
</script>
</body>
</html>