Answers for "jquery closest"

5

jquery closest

$( "li.item-a" )
  .closest( "ul" )
  .css( "background-color", "red" );
Posted by: Guest on February-20-2020
2

jquery nearest

$( "li.item-a" )
  .closest( "ul" )
  .css( "background-color", "red" );
Posted by: Guest on May-05-2020
2

closest jquery

Closest 

<div class="product">
  <div class="product-counter">
     <div class="input-group-append">

       <div class="input-group-append">
         <button class="btn btn-outline-primary product-minus" type="button"> <i class="fas fa-minus"></i> </button>
       </div>

       <input type="text" class="form-control product-number" placeholder="1" value="1">

       <div class="input-group-append">
          <button class="btn btn-outline-primary product-plus" type="button"> <i class="fas fa-plus"></i> </button>
       </div>
    </div>
  </div>   
  <button class="btn btn-light product-order"> Order + </button>
</div>

------ 
ex: i am at .product-order
 
$(document).on('click', '.product-order', function(e) {

  var counter = $(this).closest('div').find('.product-counter');
  var number = $(this).closest('div.product').find('.product-number');
  var minus = $(this).closest('div.product').find('.product-minus');
  var plus = $(this).closest('div.product').find('.product-plus');
  
});
Posted by: Guest on September-30-2021
-1

get closest element id jquery

$(".isActive").click(function() {
    var div_id = $(this).closest('tr').find('.display_image').attr(id);
    // ...
});
Posted by: Guest on January-07-2021
2

javascript find nearest element

// Find the number from `arr` which is closest to `n`
const closest = (arr, n) => arr.reduce((prev, curr) => Math.abs(curr - n) < Math.abs(prev - n) ? curr : prev);

// Or
const closest = (arr, n) => arr.sort((a, b) => Math.abs(a - n) - Math.abs(b - n))[0];

// Example
closest([29, 87, 8, 78, 97, 20, 75, 33, 24, 17], 50);   // 33
Posted by: Guest on July-02-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language