D. Giankakis D. Giankakis - 1 year ago 68
jQuery Question

Jquery stops before for loop

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();

$prod_names[$i] = $(this);

console.log("in for");
if(($prod_names[$j].height() > 20) && ($prod_names[$j].height() <= 40)){
}else if($prod_names[$j].height() > 40){

<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>
<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">&euro;</p>
<p id="low-price" class="scol50 mcol50 lcol50 price">&euro;</p>
<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>

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download