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 element | Begins with the parent element |
Travels up the DOM tree until it finds a match for the supplied selector | Travels 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 order | The 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
沒有留言:
張貼留言