jQuery if height
I have couple of divs with class "priceText" an开发者_StackOverflowd I am trying to accomplish that if div.priceText height is smaller than 100px, than hide image in this div.
I cant get this to work. I have managed to hide all images on all .priceText divs IF height in one of the .priceText divs is smaller than 100px, but I need just to hide that image witch is in this div witch is smaller than 100px.
So my unfinished code :
$(".priceText").each(function() {
var $minHeight = 100;
var $priceHeight = $('.priceText').height();
if ( $priceHeight < $minHeight) {
$("img", this).remove();
}
});
I'd do:
$(".priceText").each(function() {
var $minHeight = 100;
//you need the height of the div you are currently iterating on: use this
if ( $(this).height() < $minHeight) {
//find the img in this div and hide it
$(this).find('img').remove();
}
});
Change var $priceHeight = $('.priceText').height();
to var $priceHeight = $(this).height();
The way you have it, it is trying to get the height on all elements with a class of priceText, not the one you're currently referencing.
精彩评论