2019年2月18日 星期一

jquery table select td using closest function


1. Problem
How to select the id in the table if you using the button



2. Solution:

Using the closest() function




3.  Example:




4.  From https://api.jquery.com/closest/
.closest().parents()
Begins with the current elementBegins with the parent element
Travels up the DOM tree until it finds a match for the supplied selectorTravels up the DOM tree to the document's root element, adding each ancestor element to a temporary collection; it then filters that collection based on a selector if one is supplied
The returned jQuery object contains zero or one element for each element in the original set, in document orderThe returned jQuery object contains zero or more elements for each element in the original set, in reverse document order


5.Good example
https://codepedia.info/jquery-get-table-cell-td-value-div/


ref:
https://www.w3schools.com/jquery/traversing_closest.asp

沒有留言:

張貼留言