closest

Extract table row data with button on that row with jQuery each()

蓝咒 提交于 2019-12-11 12:48:22
问题 TLDR I want my script below to return the <input id and value of the table row that the button clicked is in. Right now it always returns the info from the first row only, regardless of which row the button was in. I think what I'm looking to do is simple, and I think I'm pretty close. But this is all a learning process for me so it's possible probable that I'm making a beginner mistake. I'm building a shopping cart. I have table rows that are built in a foreach loop. The basic gist is such

Animating invalid element's nearest divs upon form submission

核能气质少年 提交于 2019-12-11 07:45:02
问题 I've the following code, which selects the <select> elements which are not selected and prevents the form submission, if any. $("form").submit(function() { var count = 0; var selectsWithNoValue = $("select:visible").filter(function() { if (!this.value.length) { sel = this.name; if (count == 0) { alert ('Error ' + sel); ++count;} } return !this.value.length; }); return !selectsWithNoValue.length; }); Full code in JSFiddle Is it possible to find the nearest <div> to the unselected <select> and

Using jQuery closest() method with class selector

試著忘記壹切 提交于 2019-12-10 23:18:50
问题 $(this).closest(".fieldfilters"); This returns nothing for me. The HTML structure is like this: <div class="fieldfilters" > <div class="filtri_ul_list"> <ul> <li> <a></a></li> </ul> </div> </div> $(this) is the <a> . As far as I understand closest traverses the DOM up and finds the closest match. Is there a problem with the selector being a class? Why doesn't this work? 回答1: Your usage of .closest() is perfectly fine. $(this).closest(".fieldfilters"); The most probable cause of your problem

Nokogiri equivalent of jQuery closest() method for finding first matching ancestor in tree

我的梦境 提交于 2019-12-10 04:13:43
问题 jQuery has a lovely if somewhat misnamed method called closest() that walks up the DOM tree looking for a matching element. For example, if I've got this HTML: <table src="foo"> <tr> <td>Yay</td> </tr> </table> Assuming element is set to <td> , then I can figure the value of src like this: element.closest('table')['src'] And that will cleanly return "undefined" if either of the table element or its src attribute are missing. Having gotten used to this in Javascriptland, I'd love to find

Using the Jquery closest() function?

喜欢而已 提交于 2019-12-07 01:02:43
问题 Here's my HTML: <tr> <td class="show_r3c">click here</td> </tr> <tr class="r3c"> <td>This is what I'd like to display</td> </tr> And I have currently got this JQuery code, $(document).ready(function(){ $(".r3c").hide(); $('.show_r3c').click(function() { $(this).closest('.r3c').toggle(); return false; }); }); For some reason the closest() function isn't working, and it won't toggle the table row .r3c - I've tried using parent and other alternatives but can't get it working either :( Apologies

Solving a cubic to find nearest point on a curve to a point

这一生的挚爱 提交于 2019-12-06 06:33:29
问题 Ok, I have a projectile that has its position defined such that: a.x = initialX + initialDX * time; a.y = initialY + initialDY * time + 0.5 * gravtiy * time^2; I want to be able to predict which obstacles in my environment this projectile will collide with. I plan on checking the distance from A the closest point on the curve to the point P . I figure that at the point A the tangent to the curve will be perpendicular to the vector AP , and that the tangent to the curve at A will simply be the

closest() method not working as expected

余生长醉 提交于 2019-12-06 02:53:53
问题 I've a sample example below, I'm not sure why the first example (using div 's) didn't get the text when the second one (using span 's) could achieve that with the same JS code using closest() : $('.class-1').closest('div').find('.class-2').text() First snippet (using div 's) cant get the text using closest() : console.log( $('.class-1').closest('div').find('.class-2').text() ); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <div class="class-1"

closest pair algorithm

落花浮王杯 提交于 2019-12-06 00:48:57
问题 I am trying to understand the closest pair algorithm. I understand about dividing the set in half. But I am having trouble understanding how to recursively compute the closest pair. I understand recursion, but do not understand how to compute the closest pair by recursion. If you have (1,2)(1,11)(7,8) how would recursion work on these? 回答1: If you mean this algorithm you do the following: Sort points: (1,2) (1,11) (7,8) Build two subsets: (1,2) (1,11) and (7,8) Run the algorithm on (1,2) (1

Select specific closest element

社会主义新天地 提交于 2019-12-05 14:18:57
I have the following html : <table id="objects"> <tr> <td> <input type="text" value="2" /> </td> <td> <a href="#" class="delete">link</a> </td> </tr> <tr> <td> <input type="text" value="4" /> </td> <td> <a href="#" class="delete">link</a> </td> </tr> </table> When I click anchor tag I'd like to select <input> closest to my link, and get it's value. How can I do this ? I was trying : $('.delete').click(function(e){ e.preventDefault(); var val = $(this).closest('input').attr('value'); alert(val); }); but without any luck. The name of the closest function is extremely misleading: it's actually

Nokogiri equivalent of jQuery closest() method for finding first matching ancestor in tree

末鹿安然 提交于 2019-12-05 05:34:58
jQuery has a lovely if somewhat misnamed method called closest() that walks up the DOM tree looking for a matching element. For example, if I've got this HTML: <table src="foo"> <tr> <td>Yay</td> </tr> </table> Assuming element is set to <td> , then I can figure the value of src like this: element.closest('table')['src'] And that will cleanly return "undefined" if either of the table element or its src attribute are missing. Having gotten used to this in Javascriptland, I'd love to find something equivalent for Nokogiri in Rubyland, but the closest I've been able to come up with is this