Re: Updating RDFa Core

On 07/10/10 15:15, Gregg Kellogg wrote:
> I did come across one odd thing in implementing this in jQuery, I
> couldn't get attr('prefix', '...') to set the @prefix. I think that
> 'prefix' might mean something special in jQuery (the prefix of the
> element?), but don't have time to look more deeply into this. Try this
> in Firebug:
> 
>     d = $("<div><p/></div>")
>     d.children("p").attr("prefix", "dc: http://purl.org/dc/terms/")
>     d.html()
> 
>     => "<p></p>"
> 
> If you replace "prefix" with most anything else, it works okay.
> 
> Reading also poses problems:
> 
>     d = $("<div><p prefix='dc: http://purl.org/dc/terms/'/></div>")
>     d.children("p").attr("prefix")
> 
>     => null

Yeah, verified - this was really weird until we figured out what was
going on. Seems to be a bug in jQuery. I checked the source and there is
no mention of matching against a "prefix" string in the code anywhere,
however Node has a prefix attribute that is exposed via DOM Level 2:

http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-NodeNSPrefix

When you do jQuery.Node.attr("prefix", "foo"), it'll change the Node's
namespace prefix to "foo". This is not the correct behavior, AFAICT.

You can get around it by using Element.setAttribute() and
Element.getAttribute().

For example:

d = $("<div><p/></div>");
d.children("p")[0].setAttribute("prefix", "dc: http://purl.org/dc/terms/");

and

d.children("p")[0].getAttribute("prefix");

Someone might want to log a bug on jQuery...

-- manu

-- 
Manu Sporny (skype: msporny, twitter: manusporny)
President/CEO - Digital Bazaar, Inc.
blog: Myth Busting Web Stacks - PHP is Faster Than You Think
http://blog.digitalbazaar.com/2010/06/12/myth-busting-php/2/

Received on Monday, 12 July 2010 19:13:20 UTC