jquery - How to remove matching height of two divs javascript for small devices -
i've 2 divs named "a" , "b". height of both div isn't fixed. , want "b" same height "a" gets. so, put script this:
setheight($('.a'), $('.b')); function setheight(elem1, elem2) { var height = elem1.height() elem2.css('height', height); }
but small devices, don't want same height. so, i've put which not working:
$(window).on(resize, function() { if ($(window).width() > 768) { setheight($('.a'), $('.b')); } else { elem2.css('height', 'auto'); } });
what's right script it? my fiidle work
as others mentioned missing '
s around resize
elem2
undefined in function.
you need use pointer element:
$(window).on('resize', function() { if ($(window).width() > 768) { setheight($('.a'), $('.b')); } else { $('.b').css('height', 'auto'); } });
also, because don't want setheight()
run on page load if user using mobile device should check window width before calling function:
if ($(window).width() > 768) { setheight($('.a'), $('.b')); }
Comments
Post a Comment