Skip to content

Instantly share code, notes, and snippets.

@spritle
Created February 20, 2013 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spritle/4994938 to your computer and use it in GitHub Desktop.
Save spritle/4994938 to your computer and use it in GitHub Desktop.
It is a small and simple plugin which Capitalize all the text inside a table. The plugin also has the option to convert all words to small letters.
(function($) {
$.fn.tableCap = function(params) {
params = $.extend( {lower : false, toggle : true}, params);
var selectedElement = $(this);
toggleText = (function (convert) {
$('tr td',selectedElement).each(function () {
convert($(this).html(), $(this))
});
});
var Changetext = {
convertTolower : function() {
toggleText( (function(element_text, element) {
element.html(element_text.toLowerCase());
}) )
},
convertToupper : function() {
toggleText( (function(element_text, element) {
element.html(element_text.charAt(0).toUpperCase() + element_text.substring(1).toLowerCase())
}) )
}
}
params.lower ? Changetext.convertTolower() : Changetext.convertToupper();
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment