jQuery: Small utility to set CSS display type

Showing elements with jQuery's native .show() sets display as 'inline',
but sometimes we need to set 'flex' or 'inline-block'.
This commit is contained in:
Pablo Vazquez 2018-08-31 14:20:59 +02:00
parent ac3a599bb6
commit 2332bc0960

View File

@ -64,4 +64,13 @@
return this;
};
// jQuery's show() sets display as 'inline', this utility sets it to whatever we want.
// Useful for buttons or links that need 'inline-block' or flex for correct padding and alignment.
$.fn.displayAs = function(display_type) {
if (typeof(display_type) === 'undefined') {
display_type = 'block';
}
this.css('display', display_type);
}
}(jQuery));