I’m want to create a selector to find elements which have attributes starting with a string. At this point, I’m assuming this selector does not exist.
Do I need to extend the selector capabilities? Extending jQuery’s selector capabilities by James Padolsey
I need to express something like the Attribute Contains Prefix Selector [name|=”value”], but instead of matching “value”, I need to match against the name of the attribute, and not the value of the attribute.
<tag data-plugin-option1="val1" data-plugin-option2="val2" />
I’d like to end up with a syntax like this:
$('tag(:attr|="data-plugin")') which should find the element tag because it has at least one element that starts with data-plugin
Well, I guess I’m reading your question differently.
The way I read it, you want to create a custom selector that selects elements that have a given attribute name (or the start of that name).
If so, I think you’d need to iterate of the
attributescollection for each element.DEMO: http://jsfiddle.net/GgmM7/