I need to select all elements, which have an attribute starting with a given prefix - note I am talking about the attribute name, not value. For example:
<div data-abc-name="value">...</div>
<a href="..." data-abc-another="something">...</a>
<span data-nonabc="123">...</span>
In the above HTML, I need to get all elements that have an attribute starting with data-abc-
- that is, the div
and the a
.
How can I do that?
I don't think we have
jQuery
selector withregex
. However you can make use of thisUntil you find a proper selector, here is a small workaround, that selects elements with matching
attribute
You can do it like this by ES6:
Online demo (jsFiddle)
Here is my solutions - Fiddle. You have to create your own jquery selector.