I'm pretty new to js in general, but from the tutorials I've read it seems like this should work. I'm just trying to use this plugin to make 3 boxes equal height... the boxes have border-radius and some other styling applied if that matters.
Script code:
$.fn.equalHeights = function(px) {
$(this).each(function(){
var currentTallest = 0;
$(this).children().each(function(i){
if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
});
if (!px && Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
// for ie6, set height since min-height isn't supported
if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
$(this).children().css({'min-height': currentTallest});
});
return this;
};
// just in case you need it...
$.fn.equalWidths = function(px) {
$(this).each(function(){
var currentWidest = 0;
$(this).children().each(function(i){
if($(this).width() > currentWidest) { currentWidest = $(this).width(); }
});
if(!px && Number.prototype.pxToEm) currentWidest = currentWidest.pxToEm(); //use ems unless px is specified
// for ie6, set width since min-width isn't supported
if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'width': currentWidest}); }
$(this).children().css({'min-width': currentWidest});
});
return this;
};
Page code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.0.min.js"><\/script>')</script>
<script src = "js/jQuery.equalHeights.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(function(){ $('#equalize').equalHeights(); });
});
</script>
And I've applied the id of "equalize" to my div that contains the three boxes I want equal height. It doesn't seem to have an effect, and IE throws the script error "$.browser.msie is null or not an object".
I'm running this locally on a php page using xampp, if that's applicable.
I'm very sure this is just some stupid newb mistake on my part, I seriously spent like 2 hours trying to chase it down and I give up. If anyone can chime in, I'd REALLY appreciate it!
Thanks, Joe
You need jQuery Migrate for old code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With