Selecting element by data attribute
问题 Is there an easy and straight-forward method to select elements based on their data attribute? For example, select all anchors that has data attribute named customerID which has value of 22 . I am kind of hesitant to use rel or other attributes to store such information, but I find it much harder to select an element based on what data is stored in it. 回答1: $('*[data-customerID="22"]'); You should be able to omit the * , but if I recall correctly, depending on which jQuery version you’re