I'd like to be able to set default placeholders for string really easily like this
someString.placeholder("waiting for text")
Which could be used like this...
$("p.some-class").html( someString.placeholder("waiting for text") );
so if 'someString' is empty, the user sees "Waiting for text", but if the string has a length greater than 0, they see the actual string.
I've tried to extend the String object like this
String.prototype.placeholder = function(placeholder){
return (this.length > 0) ?
this :
"<span class=\"placeholder-string\">" + placeholder + "</span>";
}
but that doesn't appear to be working. Any thoughts anyone?
Here's a JSFiddle for anyone who's interested.
spantag?someString || "waiting for text"?placeholdernotplaceHolder. I can't see any other problems with it.