user2254306
user2254306

Reputation: 21

jQuery TypeError: a.style is undefined when loading svg file in Firefox 20.0

I work with SVG file. SVG file has xlink-ed jQuery.

When opening svg file in Firefox 20.0 I get error

TypeError: a.style is undefined

If I open svg file in Firefox 19 and older versions, no errors appears.

Any ideas why jQuery with svg is not working in FF20.0?

My SVG demo file

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink"
     width="467" height="462">

  <rect x="80" y="60" width="250" height="250" rx="20"
      style="fill:#ff0000; stroke:#000000;stroke-width:2px;" />

  <rect x="140" y="120" width="250" height="250" rx="40"
      style="fill:#0000ff; stroke:#000000; stroke-width:2px;
      fill-opacity:0.7;" />

  <script
     xlink:href="http://code.jquery.com/jquery-1.9.1.js"
     id="script10"
     type="text/javascript" />
</svg>

Upvotes: 2

Views: 1494

Answers (2)

Vinicius Garcia
Vinicius Garcia

Reputation: 1748

As said by @Boris in the other answer, this is due by a jquery bug.

In this link you can see more information about it.

One of the comments suggests the following (in jquery-1.9.1):

In jquery-1.9.1, line 1321, change from this:

if ( !all || !a || !all.length ) {

To this:

if (!all || !a || !all.length || !a.style) {

His explanation:

This should cause the jQuery.support function to return {} (an empty object), as it seems to do on other browsers. In FF19, "!a" evaluates to true. In FF20 "!a" evaluates to false, but a.style is undefined. So checking for !a.style should avoid the error here.

This has solved my problem!

Note: It's not a good practice to change third-party code, but I didn't find any better solution by now.

Upvotes: 0

Boris Zbarsky
Boris Zbarsky

Reputation: 35064

This is due to jQuery assuming it's running in an HTML document, basically. See http://bugs.jquery.com/ticket/13754

Upvotes: 2

Related Questions