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.

  1. you don't close <div class='my_class'>
  2. 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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -