[jQuery] Creating a Function based on text argument
I've been looking around and besides my best efforts I haven't been
able to figure it out.
All the function extending I see extends on an _object_.
I want to extend on a string.
/**
* Returns a slug version of a string
*/
jQuery.extend ({
slug: function( text ) {
return text.trim().toLowerCase().replace( /[^-a-zA-Z0-9\s]/g,
'' ).replace( /[\s]/g, '-' );
}
});
I want to be able to do something like:
$('#form_element').val().slug();
The above does not work. I even tried modifying the 'trim' function in
jQuery core to include the rest of the enhancements, but it didn't
work.