jQuery: How to Iterate Over Children of Closest Element
The problem with the code is that the 'closest' method returns a single element, not a collection of elements. Therefore, there is no need to use the 'each' function afterwards.
To achieve the desired result, you can modify the code as follows:
$('#'+item_id).closest('.qcart_item').find('.qq_item_data').each(function() {
// code to be executed for each qq_item_data element
});
In this code, $('#'+item_id) selects the element with the specified item_id, closest('.qcart_item') finds the closest ancestor element with the class 'qcart_item', and find('.qq_item_data') selects all descendant elements with the class 'qq_item_data'. The 'each' function then iterates over each of these elements.
原文地址: https://www.cveoy.top/t/topic/qc9n 著作权归作者所有。请勿转载和采集!