get the highest value, and then filter results by class in jquery -
i'm trying highest value stored between strong tags, , filter results class "condition ok" in jquery. can me problem please?
<div id="my_list"> <div class="my_class"> <div> <p> <strong>12</strong> </p> <p class="condition ok"></p> </div> <div class="my_class"> <div> <p> <strong>10</strong> </p> <p class="condition ok"></p> </div> <div class="my_class"> <div> <p> <strong>25</strong> </p> <p class="condition"></p> </div> <div class="my_class"> <div> <p> <strong">20</strong> </p> <p class="condition ok"></p> </div>
looks have error @ html.
- you don't close
<div class='my_class'>
- last strong element has unnecessary double quote
after then, take @ fiddle result : https://jsfiddle.net/2hf2qt2j/
var max = -1; $("strong").each(function(){ if($(this).parent().next("p").is('.condition.ok')) max = math.max(max, $(this).text()); }); alert(max);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="my_list"> <div class="my_class"> <div> <p> <strong>125</strong></p> <p class="condition ok"></p> </div> </div> <div class="my_class"> <div> <p> <strong>10</strong></p> <p class="condition ok"></p> </div> </div> <div class="my_class"> <div> <p> <strong>525</strong></p> <p class="condition"></p> </div> </div> <div class="my_class"> <div> <p> <strong>20</strong></p> <p class="condition ok"></p> </div> </div>
update
if strong has negative value, take here https://jsfiddle.net/y09vq8p5/
Comments
Post a Comment