Questions tagged [closest]

Closest is being the nearest to a number, object, quantity etc.

Given a number of objects, the closest 2 objects would be those that the between them is the shortest.

561 questions
35
votes
4 answers

Using a class name in jQuery's .closest()

I'm attempting to do some calculations for a "running total", this is my code: $('.quantity_input').live('change',function(){ var ValOne = parseFloat($(this).val()); var ValTwo =…
benhowdle89
  • 36,900
  • 69
  • 202
  • 331
32
votes
4 answers

Finding k closest numbers to a given number

Say I have a list [1,2,3,4,5,6,7]. I want to find the 3 closest numbers to, say, 6.5. Then the returned value would be [5,6,7]. Finding one closest number is not that tricky in python, which can be done using min(myList, key=lambda…
frazman
  • 32,081
  • 75
  • 184
  • 269
26
votes
4 answers

Efficiently finding the closest coordinate pair from a set in Python

The Problem Imagine I am stood in an airport. Given a geographic coordinate pair, how can one efficiently determine which airport I am stood in? Inputs A coordinate pair (x,y) representing the location I am stood at. A set of coordinate pairs…
Kieran
  • 2,554
  • 3
  • 26
  • 38
26
votes
2 answers

jQuery closest(); not working

I am trying to do make some text show when a text input is on focus, but the closest(); method doesn't seem to be working. I have done a JS Fiddle for you to look at. and here is the code also. JS $(document).ready(function(){ …
Ollie2619
  • 1,255
  • 4
  • 17
  • 28
25
votes
3 answers

JQuery: Closest div that has an ID

How would you write the Jquery to get the closest div that actually has an ID defined?
mike
  • 283
  • 1
  • 4
  • 8
25
votes
3 answers

Closest date in a vector to a given date

I would like to identify the closest date in a vector of given date. Let's say I have the following date vector (with 5 random dates): coldate= as.Date(c("2013-08-03", "2013-09-04", "2013-09-08", "2013-09-12", "2013-11-01")); Now, I want to find…
Henri
  • 1,571
  • 5
  • 23
  • 38
22
votes
6 answers

How do I find values close to a given value?

I have data = [1 1.2 1.3 1.5 1.8] I want to find closest values before and after from data for this point, b = 1.23 How do I do this?
nsy
  • 251
  • 2
  • 3
  • 4
22
votes
4 answers

Opposite to jQuery's .Closest (Top/Far-Most?)

I have a code with lots of submenus that share the same class name. Here's a structure: .menu .sub-menu .sub-menu .sub-menu .sub-menu .sub-menu .sub-menu .elem .elem .sub-menu Note that .sub-menu may be infinite…
Dzhuneyt
  • 8,437
  • 14
  • 64
  • 118
21
votes
3 answers

jQuery: find input field closest to button

I have a large HTML form with multiple input fields (one in each row). Among these I have several fields with a specific class that appear left from a button. There are no other buttons or fields in these rows so they only contain the field and…
user2571510
  • 11,167
  • 39
  • 92
  • 138
19
votes
2 answers

Get first matching ancestor containing a specific class

I am trying to iterate to the first ancestor containing the class ‘sys-form-row’. I am able to get the row containing class="sys-form-row" using the following: objBack = $('#txtMyBox2').parent().parent(); This seems incredibly clumsy. What I…
user831839
  • 247
  • 3
  • 6
17
votes
3 answers

How to get a value of the closest td with class on button click?

I have table rows with data and buttons. http://codepen.io/leongaban/pen/nuIkd Each button corresponds to each row, also when you click a button it changes class names from hide to un_hide the next step is to retrieve the text value of the td with…
Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
15
votes
4 answers

Get the ID of a form?

I'm using the following code to attach an event to the submit button of a form : $('form.manage-users-form').on('click','button.special',function() { if ($(this).hasClass('selected')){ console.log('This user is already special'); }…
Roland
  • 9,321
  • 17
  • 79
  • 135
14
votes
2 answers

Using numpy.argmax() on multidimensional arrays

I have a 4 dimensional array, i.e., data.shape = (20,30,33,288). I am finding the index of the closest array to n using index = abs(data - n).argmin(axis = 1), so index.shape = (20,33,288) with the indices varying. I would like to use data[index]…
NPB
  • 143
  • 1
  • 4
14
votes
4 answers

Closest value to a specific column in R

I would like to find the closest value to column x3 below. data=data.frame(x1=c(24,12,76),x2=c(15,30,20),x3=c(45,27,15)) data x1 x2 x3 1 24 15 45 2 12 30 27 3 76 20 15 So desired output will be Closest_Value_to_x3 24 30 20 Please help.…
melik
  • 1,268
  • 3
  • 21
  • 42
14
votes
4 answers

Does d3 have api which similar with jQuery.closest(selector)?

DOM like this: I didn't find the closest API: https://github.com/mbostock/d3/wiki/API-Reference How can I get the nearest matched elements from it's parent? Just like this: var module =…
Kris Zhang
  • 307
  • 2
  • 6
1
2 3
37 38