Skip to content

Instantly share code, notes, and snippets.

@Jerph
Created March 4, 2013 21:15
Show Gist options
  • Save Jerph/5085737 to your computer and use it in GitHub Desktop.
Save Jerph/5085737 to your computer and use it in GitHub Desktop.
jquery plugin for accessing val(), or if that's empty, text(). Also calls the write version of both functions. Useful for changing the displayed text on buttons that can be either inputs or links.
jQuery.fn.valOrText = function (textString) {
if (textString === undefined) {
if (this.length == 0)
return this.val();
else
return this.val() || this.text()
} else {
this.val(textString);
return this.text(textString);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment