Bug Tracker

Opened 12 years ago

Last modified 12 years ago

#9392 closed feature

Add :data() Selector — at Initial Version

Reported by: kaneiderdaniel@… Owned by:
Priority: low Milestone: 1.7
Component: selector Version: 1.6.1
Keywords: 1.7-discuss Cc:
Blocked by: Blocking:


Provide a selector for .data(), similar to those of attributes:

Example with attributes

  • $("".someClass[myAttr])
  • $("".someClass[myAttr='someValue'])

Likewise something for .data

  • $("".someClass:hasData(myAttr))
  • $("".someClass:data(myAttr='someValue'))

You can avoid the need for this, if you use custom data attributes, as and only as DOM attributes: <div id=""test"" data-test=""value""></div> .. $(""#test[data-test='value'])

But if you start using the .data() function, this is no longer possible in such a way: <div id=""test""></div> .. $(""#test"").data(""test"", ""value"") $(""#test[data-test='value']) fails

Alternative: $(""*"").filter(function() { return $(this).data(""test"") === ""value""; });

There is a already a plugin which implements this problem, which I would like to see included in $1.7 in some way... http://plugins.jquery.com/project/dataSelector

Change History (0)

Note: See TracTickets for help on using tickets.