Last Updated on September 29, 2020
[code]
<?php
add_action( ‘wp_footer’, ‘make_same_height’ );
function make_same_height() {
?>
<script type=”text/javascript”>
jQuery(document).ready(function() {
jQuery(document).ready(function() {
var maxHeight = -1;
jQuery(‘.equal-height-elements .wpb_wrapper .equal-height’).each(function() {
maxHeight = maxHeight > jQuery(this).height() ? maxHeight : jQuery(this).height();
});
jQuery(‘.equal-height-elements .wpb_wrapper .equal-height’).each(function() {
jQuery(this).height(maxHeight);
});
});
});
</script>
<?php
}[/code]
Equal Height VC Elements
With WPBakery you can have equal height columns where each column is the same height but they don’t have a way to do equal height elements. So let’s pretend you have 3 columns with each column having an image, description, and a button. If you wanted the buttons to all line up vertically then the descriptions would have to be pretty much the same length but if one is much longer than the others then the buttons won’t line up. Especially on responsive websites. Well the following function/javascript will resize the smaller elements to be the same height as the largest one. You just need to add the class “equal-height-elements” to the element and then within FTP you need to create a file in the mu-plugins folder and paste this code in that php file you created. You could also add the inner part of the code to the child-theme functions.php file as well.
JavaScript Pieces
.getElementById
You can only use this once per page since IDs are supposed to be unique and only have one of these. If you have multiple matching IDs on a page then it only applies to the first one.
.getElementsByClassName(“example”)[0]
ClassName can be an array so doing the [0] grabs just the first object found with that class. I assume that if there were multiple and you wanted the second then you would do [1] and so forth or if you want all of them then remove it altogether?
.getElementsByTagName(‘img’)[0]
This one is used to grab a specific element that doesn’t have a class or ID. This one is grabbing the first img tag.