Skip to content

ProtoString cleanId() Method

Seth Clydesdale edited this page May 23, 2015 · 2 revisions

<< Back to DOM Node Methods

Example

Cleaning a string of text, so that it can be used as a valid identifier.

var id = 'my identifier!'.cleanId(); // returns 'my-identifier'
var node = document.createElement('DIV');

node.id = id; // apply the cleaned string as the ID

Description

The cleanId method can be used to clean a string of text, so that it can later be used as the id or href attribute of an element. This method removes characters considered "illegal." All alphabetical characters are kept, as well as dashes and underscores, whereas whitespace is converted to a dash and illegal characters are stripped.

Syntax

String.cleanId();
Clone this wiki locally