GetValueWithDataAttr 1

GetValueWithDataAttr

$(this).attr("data-id") // will return the string "123"

Here is what the above code is Doing:
1. We’re using the jQuery selector to find all elements with the class “delete-item”.
2. We’re using the jQuery on() method to attach a click event handler to all elements with the class “delete-item”.
3. We’re using the jQuery attr() method to get the value of the data-id attribute of the element that was clicked.
4. We’re using the jQuery closest() method to find the closest ancestor that matches the given selector. In this case, we’re finding the closest ancestor that has the class “item”.
5. We’re using the jQuery remove() method to remove the element that was clicked.

Similar Posts