#3116 closed bug (fixed)
.attr does not work with SVG IDLs
Reported by: | atrax | Owned by: | Timmy Willison |
---|---|---|---|
Priority: | high | Milestone: | 1.6 |
Component: | attributes | Version: | 1.5.2 |
Keywords: | .attr SVG read-only | Cc: | |
Blocked by: | Blocking: | #7584 |
Description
The function .attr does not work with read only interfaces of SVG specification. If you try to set a attribute that is present in a SVG IDL you get an error about setting a property for which only a getter is defined.
In previous versions of JQuery the DOM IDL setAttribute would have been used to set cx for circle. In JQuery 1.2.6 circle[cx] is used which maps to the SVG IDL: read only property.
A simple example:
<!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.1 plus MathML 2.0 plus VG 1.1EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="jquery-1.2.6.js" />
<script type="text/javascript">
function test()
{
$('circle').attr("cx", "1");
}
</script> <title>
Demo
</title>
</head>
<body onload = "test();">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://
www.w3.org/1999/xlink" version="1.1" baseProfile="full" width="3000" height="3000">
<circle cx="200px" cy="200px" r="150px" />
</svg>
</body>
</html>
Attachments (1)
Change History (17)
comment:1 Changed 15 years ago by
comment:2 Changed 15 years ago by
Firefox does nothing visible for the user but on the error console it shows an error that I tried to set a property for which only a getter is defined.
Error: setting a property that has only a getter Source file: http://fsmat.at/~atrax/jquery-1.2.6.js Zeile: 1070
You can see my little example online: http://fsmat.at/~atrax/JQuery-Test.xhtml
comment:3 Changed 15 years ago by
Owner: | set to flesler |
---|---|
Status: | new → assigned |
Ok, I think we need to treat SVG nodes as xml elements... this could just mean extending $.isXmlDoc a bit.
comment:4 follow-up: 5 Changed 15 years ago by
need: | Review → Patch |
---|
I can't really reproduce this as I don't know how to use svg. I tried this on FF 3 but no luck.
Can you please apply the following patch to your jQuery version and see if that solves it ? Then, let me know.
Cheers
Changed 15 years ago by
Attachment: | attr[5790].diff added |
---|
comment:5 Changed 15 years ago by
I tried your patch but it won't work this way. The problem is that you only check for 'svg' element (where nodeName is svg). The problem, however, persists for elements that are defined in svg (like 'circle' in my example).
If you look at my example there is only one line of svg code; a circle. circle is a tagname defined in svg and therefore has the abovementioned behaviour that its defined attributes are not set-able via the svg interface (elem[attrname] = value, compare jquery line 1070); you have to use the standard DOM interface (elem.setAttribute (attrname, value), compare jquery line 1085).
Please have a look at SVG-specs and search for 'SVGCircleElement'. There you will find the source of the problem (as far as I understand it):
interface SVGCircleElement : SVGElement, SVGTests, SVGLangSpace, SVGExternalResourcesRequired, SVGStylable, SVGTransformable, events::EventTarget { readonly attribute SVGAnimatedLength cx; readonly attribute SVGAnimatedLength cy; readonly attribute SVGAnimatedLength r; };
I hope that you will find a solution. I will keep looking for one too :-)
regards
Replying to flesler:
I can't really reproduce this as I don't know how to use svg. I tried this on FF 3 but no luck.
Can you please apply the following patch to your jQuery version and see if that solves it ? Then, let me know.
Cheers
comment:8 Changed 13 years ago by
Blocking: | 7584 added |
---|
comment:9 Changed 12 years ago by
Milestone: | 1.3 → 1.next |
---|---|
Owner: | flesler deleted |
Priority: | major → high |
Status: | assigned → open |
Version: | 1.2.6 → git |
comment:10 Changed 12 years ago by
I have been setting attributes successfully, so invested some time to reproduce this bug report in jQuery 1.2.5, 1.2.6, and 1.3, but confirm that jQuery 1.3.1 and 1.5.1 work correctly.
Here are a few details to help a team member confirm that this ticket can be closed:
1.2.4 attr:
// Certain attributes only work when accessed via the old DOM 0 way if ( fix[ name ] ) { This does not apply to SVG elements. // IE elem.getAttribute passes even for style else if ( elem.tagName ) { Calls to getAttribute and setAttribute succeed.
1.2.5 attr:
// If applicable, access the attribute via the DOM 0 way if ( notxml && !special && name in elem ) { Value of notxml is incorrect for SVG in XHTML5. It had also been incorrect in 1.2.4 but now it makes a difference. The following assignment throws an exception: elem[ name ] = value;
1.3.1
// If applicable, access the attribute via the DOM 0 way if ( name in elem && notxml && !special ) { Value of notxml is correct because of change to isXMLDoc. This does not apply to SVG in XHTML5 any more. The following calls to getAttribute and setAttribute succeed. if ( set ) // convert the value to a string (all browsers do this but IE) see #1070 elem.setAttribute( name, "" + value ); var attr = !jQuery.support.hrefNormalized && notxml && special // Some attributes require a special call on IE ? elem.getAttribute( name, 2 ) : elem.getAttribute( name );
Here is a jsFiddle, but sadly it doesn't directly show the meat of the issue because the file is HTML5 instead of XHTML5 (that is, served as XML in addition to having the HTML5 DOCTYPE).
comment:11 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | open → closed |
Per mpedrotti, the issues mentioned in this bug report only appear to affect quite old versions of jQuery (pre 1.3.1) as I can confirm.
As the .attr() problems related to SVG IDLs seem to be ironed out in the releases over the past year or so (and we're obviously unable to patch 1.2.x), we'll be closing this ticket as fixed.
If for any reason we've missed something, please feel free to re-open if required.
comment:12 Changed 12 years ago by
Milestone: | 1.next → 1.6 |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
Version: | git → 1.5.2 |
comment:13 Changed 12 years ago by
Owner: | set to Timmy Willison |
---|---|
Status: | reopened → assigned |
I've confirmed this is still an issue in 1.5.2, but it is fixed in attrhooks for 1.6.
comment:15 Changed 12 years ago by
Component: | core → attributes |
---|
comment:16 Changed 12 years ago by
only $("#elementID").attr() works, but $(".elementclass").get(0).attr() not work
Do you actually get an error ? or attr() simply does nothing ?