Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get elements that begin with a common class prefix, group them accordingly, and equalize their heights to their max height
var cousins = [];
// Find all elements that begin with class and return just that matching class
$('[class^=equalize-').each(function(index, el, array) {
var group = $(el).attr('class').match(/\bequalize-[\S]*/);
if ( group.length ) {
cousins.push( group[0] );
// Make list of matched element classes unique
cousins = cousins.filter(onlyUnique);
// Equalize elements
$(window).on('resize', function(){
function equalize(groupName) {
var maxHeight = 0;
$('.' + groupName).each(function(){
if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.