I'm trying to target attributes names which contains a certain word & not in the kind of way you're thinking.
Lets say I have:
<div data-foo-bar="hello"></div>
How can I target elements which have 'data-foo'
in the attribute name?
I'm trying to target attributes names which contains a certain word & not in the kind of way you're thinking.
Lets say I have:
<div data-foo-bar="hello"></div>
How can I target elements which have 'data-foo'
in the attribute name?
This is just an alternative solution. If you can ensure the attribute's name you're looking for is not present in the element text, what you could do is getting the outerHtml value of the element and then make a substring search:
Hope this helps.
Try something like this
Try this
HTML:
I'm not sure you can do that. I've had a peek at the API and you only seem to be able to do deeper partial matching on the value, not the attribute name itself.
I'm going to give you the potentially frustrating advice of, "don't do this". ;-) In essence, what you're after is a bunch of divs that match a more general category. Not just
data-foo-bar
s, but ALLdata-foo
s! Why not just give all data-foos a classname that you can select from, or a separate attribute likedata-foo="true"
?In other words, rather than sticking strictly to the question as asked, I'd be curious to know what the use case is so that maybe a lateral move in thinking can solve your problem just as effectively. Many ways to skin a cat and all that.
Use
.data()
to get all the data attributes of an element, and then use.filter
to get the elements that havedata-validation*
attributes.I don't think you can target attribute names the same way you target attribute values. You can, however, use
.filter()
to do this somewhat efficiently:Notice that
data-foo-bar
has been converted tofooBar
.Demo: http://jsfiddle.net/Tyj49/3/