Monday, September 29, 2008

[jQuery] Re: Metadata parameter as selector

The previous responses don't seem to get that you're using the metadata plugin. I would suggest using filter:
 
$('tr').filter(function() { return $(this).metadata().id == 4; })...
 
If you find yourself doing that a lot, you can add a custom selector for metadata. Something like:
 
jQuery.extend(jQuery.expr[':'], {
     meta: "!m[3]||((p=m[3].split('='))&&(p.length>1?$(a).metadata()[p[0]]==p[1]:$(a).metadata()[p[0]]))"
});
Which you could then use like:
$('tr:meta(id=4)')...
 
I put together a little test page:
 
 
Seems to work in IE7 and FF3. Untested elsewhere.
 
Hope it helps.
 
--Erik

 
On Mon, Sep 29, 2008 at 10:23 AM, me-and-jQuery <brilko.brilko@gmail.com> wrote:

I am searching the web and documentation and still can't find a
working solution.

I have a table which rows has also id with metadata, for example <tr
data="{id:4}">

And now I want to select row with id 4. I was trying many ways but no
success for now. For example:

$.metadata.setType("attr", "data")
$("table tr.id:4").metadata().remove();


Anyway, is this possible with metadata at all? Thanks for any help.

No comments: