Those bracket and dots selectors are very confusing, why not something
simple like $('div:data(foo)') and $('div:data(foo!=dido)') ?
Meanwhile, you can use a simple plugin (WTFPL licensed):
$.fn.hasData = function(){
var a = arguments;
return this.filter( (a[1])
? function(){ return $(this).data(a[0]) == a[1] }
: function(){ return $(this).data(a[0]) } );
};
$('div').hasData('taxi');
$('div').hasData('chocolate','yesplease');
- ricardo
On Nov 3, 7:17 pm, Danny <[EMAIL PROTECTED]> wrote:
> It's far easier to extend jQuery.expr[':'] than to extend the []
> syntax, because the latter is hard-wired into jQuery.filter . You
> would have to push a new regExp onto jQuery.parse before the usual []
> regExp, something like (using Ariel's [: syntax) :
>
> jQuery.parse.push ( /(\[:)([\w-]+)\s*([!*$^~=]*)\s*('?"?)(.*?)\4\s*
> \]/) ;
>
> jQuery.expr['[:'] = function (a, i, m) { /* filtering function as
> above,m[2] == key, m[3] == type, m[5] == test string */ };
>
> (not tested)
>
> Haven't played with Sizzle to see if it's easier.
>
> Danny (What adult still goes by Danny?)
>
> On Nov 3, 11:26 am, Danny <[EMAIL PROTECTED]> wrote:
>
> > On Nov 3, 12:07 pm, Danny <[EMAIL PROTECTED]> wrote:
>
> > > Danny (a different Danny than the one who started the thread!)
>
> > Way too many of 'em around!
>
> > Question, why use the data() syntax in the selector instead of the []
> > syntax suggested earlier in the thread?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---