I want to dynamically change the value of text from my SVG built in illustrator. I've tried many examples on the web, but they don't actually work. Has someone at Adobe, using the new pack done this?
Thanks. That was definitely part of the answer. I'm going to answer the rest for completeness. The other part was how the SVG was loading the javascript. Assuming WebKit-based browsers, I had to link the external javascript file from inside the SVG, not the HTML document (which wouldn't work). In HTML, I used:
<object id="mydata" name="mydata" type="image/svg+xml" data="mydata.svg" width="320px" height="100px" />
Then inside the SVG file, I linked the js file, and added an onload event, which happens after parsing, before rendering:
<svg version="1.1" id="mainLayer" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="100%" height="100%" viewBox="0 0 320 100" enable-background="new 0 0 320 100" xml:space="preserve" onload="init(evt)">
<script xlink:href="test.js" type="text/ecmascript" encoding="utf-8"/>
Then inside the javascript file:
function init(evt) {
// sample call
changeText("change my text");
}
function changeText(value) {
var svgText;
svgText = document.getElementById("varMyData").firstChild;
svgText.nodeValue = value;
}
While this may not be the only way to make it work, it's a least one way.
North America
Europe, Middle East and Africa
Asia Pacific