The strip_tags(), and stripslashes() functions are generally known and used in PHP. These functions are useful when working with strings that contains HTML code, but JavaScript doesn't have such functions.
Here's these functions for JavaScript.

strip_tags

strip_tags(string, allow) - returns a string with HTML and PHP tags stripped from a given string. HTML comments are also stripped.
The allow parameter is optional, and represents a string with allowable tags, which should not be stripped (a string like: "<b><i><u>").
Code:
function strip_tags(str, allow) {
  // making sure the allow arg is a string containing only tags in lowercase (<a><b><c>)
  allow = (((allow || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join('');

  var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi;
  var commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
  return str.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {
    return allow.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
  });
}

Example:
<div id="sresult"></div>
<script type="text/javascript"><!--
// strip_tags - from www.phpjs.org
function strip_tags(str, allow) {
  // making sure the allow arg is a string containing only tags in lowercase (<a><b><c>)
  allow = (((allow || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join('');

  var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi;
  var commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
  return str.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {
    return allow.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
  });
}

var str = '<p>Test paragraph.</p><!-- Comment --> <a href="http://coursesweb.net/">CoursesWeb.net</a>.<br/>New line: <b>Bold</b>, and <u>Underline</u>. An opening Span tag: <span>*';

var str1 = strip_tags(str);                  // removes all tags
var str2 = strip_tags(str, '<b><u>');        // keeps <b> and <u> tags

// adds str1 and str2 in webpage
document.getElementById('sresult').innerHTML = 'str1: '+ str1+ '<br/>str2: '+ str2;
--></script>
Result:
str1: Test paragraph. CoursesWeb.net.New line: Bold, and Underline. An opening Span tag: *
str2: Test paragraph. CoursesWeb.net.New line: Bold, and Underline. An opening Span tag: *

stripslashes

stripslashes() - un-quotes a quoted string. Returns a string with backslashes stripped off. (\", and \' become " and ') Double backslashes (\\) are made into a single backslash (\).
Code:
function stripslashes(str) {
 return str.replace(/\\'/g,'\'').replace(/\"/g,'"').replace(/\\\\/g,'\\').replace(/\\0/g,'\0');
}

Example:
<script type="text/javascript"><!--
// stripslashes
function stripslashes(str) {
 return str.replace(/\\'/g,'\'').replace(/\"/g,'"').replace(/\\\\/g,'\\').replace(/\\0/g,'\0');
}

var str = 'String with \"backslashes\", \\ coursesweb.net/';
str = stripslashes(str);

alert(str);       // String with "backslashes", \ coursesweb.net/
--></script>

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag adds a new line into a paragraph?
<b> <br> <p>
First line ...<br>
Other line...
Which CSS property can be used to add space between letters?
text-size word-spacing letter-spacing
#id {
  letter-spacing: 2px;
}
What JavaScript function can be used to get access to HTML element with a specified ID?
getElementById() getElementsByTagName() createElement()
var elm = document.getElementById("theID");
var content = elm.innerHTML;
alert(content);
Click on the "echo" correct instruction.
echo "CoursesWeb.net" echo "CoursesWeb.net"; echo ""CoursesWeb.net";
echo "Address URL: http://CoursesWeb.net";
JavaScript strip_tags and stripslashes

Last accessed pages

  1. Select in MySQL, Output results in HTML Table (1419)
  2. Golf Putt It In (739)
  3. Disable button and Enable it after specified time (5129)
  4. Flash Games - Free online Games (22975)
  5. Move image from an element /tag to another (1637)

Popular pages this month

  1. Qwop (3219)
  2. Get Attribute (ID, Class, Name, Title, Src) with jQuery (2547)
  3. Get the value of the selected /checked checkboxes in a form (1608)
  4. Insert, Select and Update NULL value in MySQL (1423)
  5. Add, Change, and Remove Attributes with jQuery (1301)