Reputation: 173
i am trying to adjust a div font-size depending on its height
i get the elements with class "prod-name" with .each
$prod_names = new Array();
$i=0;
$j=0;
$(".prod-name").each(function(){
$prod_names[$i] = $(this);
$i++;
});
for($j=0;$j>=$i;$j++){
console.log("in for");
if(($prod_names[$j].height() > 20) && ($prod_names[$j].height() <= 40)){
console.log("ok");
$prod_names[$j].css("font-size","0.9em");
}else if($prod_names[$j].height() > 40){
$prod_names[$j].css("font-size","0.8em");
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="mostviewed" class="products">
<h2 class="cat-title">MOST VIEWED</h2>
<ul>
<li class="scol25 mcol25 lcol25" >
<a href="product.php" class="prod-img"><img src="images/products/.jpg" title=""/></a>
<p class="prod-name">Intel Core I3</p>
<div class="prices">
<p id="original-price" class="scol50 mcol50 lcol50 price">€</p>
<p id="low-price" class="scol50 mcol50 lcol50 price">€</p>
</div>
<div class="fa-buttons">
<a id="morea" class="scol50 mcol50 lcol50 add1" title="More information" href="product.php"><i class="fa fa-search" aria-hidden="true"></i></a>
<a id="fava" href="#" class="scol50 mcol50 lcol50 add1" title="Add to favorites"><i class="fa fa-heart" aria-hidden="true" ></i></a>
</div>
</li>
</ul>
</div>
i added logs to see if it reaches the code in the loop and it doesnt
note: in reality i use php but for better understanding of my problem i changed it to html
Thank you
Upvotes: 0
Views: 38
Reputation: 173
i see so one of the parameters of the for loop is false...
thank you, i know the code is extended and complicated but im a beginner in jquery and as i go on i will make the code better
thank you
Upvotes: 0
Reputation: 11102
You have a problem with the logic here... Assuming there are 4 prod-name
elements, then $i will be 4, while $j is 0, so $j>=$i
is false hence won't get in the loop..
I bet you shall reconsider the aim of this code and write it in a neater way.
Upvotes: 1