2

Is there any way I can run jQuery under SVG instead of HTML?

I know about jQuery svg plugin but this is not what I want.

As for now the jQuery engine contains some statements like this:

div = document.createElement("div"); div.style.display = "none"; 

It fails with exception during jQuery initialization under SVG because SVG document is unable to create div element. And there are some other HTML-specific places in jQuery which fail in unpredictable places under SVG.

Is there any way to resolve this problem?

1 Answer 1

3

I hacked an old version of jquery around a bit, and it is possible to run it in svg-only mode with some modifications. Feel free to take the changes and do whatever you want with them. Here's a demo and here's the modified jquery sourcecode.

It's incomplete and probably has some issues if you want to use it in both HTML and SVG, but it's a start, and works to some extent at least.

Sign up to request clarification or add additional context in comments.

4 Comments

There was one more issue with classes of elements. Class selectors and methods didn't work because in HTML elem.className is a string but in SVG it is an object. String class is taken from elem.className.baseVal. I have patched newest (1.4.2) version of jQuery. One more issue is that SVG doesn't call initialization methods so I introduce jQueryInitialize and call it in onload. Here is a link: hgcoaxial.appspot.com/static/jquery-1.4.2.svg.js to the patched jQuery. And here is more sophisticated example: hgcoaxial.appspot.com/static/jquery-1.4.2.svg.js of jQuery under SVG.
Thanks, almost works, only - how do I animate e.g. position of a circle? jQuery works with CSS attribs, and circle's cx / cy has no CSS counterpart IIUC. I've tried top but no effect (although does not throw).
@Volodymyr, thanks for the link. Do you plan on keeping this updated? I have real use for this and would love to see it become official.
@zourtney, thanks for feedback. Yes, I think about making it official, and keep it updated. But I relay need help on this, I don't have enough time to make it alone.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.