php&javascript - how to highlight the lowest value -


my goal , highlight lowest value between decimals within li.

<ul class="list-group">     <li class="list-group-item" style="border:2px solid ;" data-distance="31.5">test 31.5</li>     <li class="list-group-item" style="border:2px solid ;" data-distance="21.5">test 21.5</li>     <li class="list-group-item" style="border:2px solid ;" data-distance="11.5">test 11.5</li>     <li class="list-group-item" style="border:2px solid ;" data-distance="51.5">test 51.5</li>     <li class="list-group-item" style="border:2px solid ;" data-distance="61.5">test 61.5</li>     <li class="list-group-item" style="border:2px solid ;" data-distance="11.5">test 11.5</li> </ul> 

my code:

  <script type='text/javascript'> $(window).load(function() {     $($("[data-distance]").get().sort(function(a, b)      {         return a.getattribute("data-distance") - b.getattribute("data-distance");     })[0]).css("border-color", "red");  }); </script> 

this code fails if multiple li has same min value. want highlight each min value— how can this?

try this:

// lowest value first var low = $("[data-distance]").get().sort(function(a, b) {     return a.getattribute("data-distance") - b.getattribute("data-distance"); })[0].getattribute("data-distance");  // loop through , update match lowest $("[data-distance]").each(function(a){     if (this.getattribute("data-distance") == low) {         $(this).css("border-color", "red");     } }); 

demo: http://jsfiddle.net/grydawp4/1/


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -