473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

SVG Text Manipulation with JavaScript

Hi All,

I am creating a custom chart using SVG and I am having problems while dealing with text on IE. I have the SVG file being loaded through an EMBED tag and I can access it through JavaScript. This is a line chart and the lines are being positioned correctly. The problem is that I want to change the text of the scale to the values on the JavaScript, but I can't make it work on IE.

Below is the code snippet that handles this:
Expand|Select|Wrap|Line Numbers
  1. var newText = svg_doc.createElementNS(svgNS,"text");
  2.     newText.setAttributeNS(null,"x",100);        
  3.     newText.setAttributeNS(null,"y",100);    
  4.     newText.setAttributeNS(null,"font-size","13px");
  5.     newText.setAttributeNS(null,"text-anchor","middle");
  6.     newText.setAttributeNS(null,"fill-opacity",Math.random());        
  7.     var red = Math.round(Math.random() * 255);
  8.     var green = Math.round(Math.random() * 255);
  9.     var blue = Math.round(Math.random() * 255);
  10.     newText.setAttributeNS(null,"fill","rgb("+ red +","+ green+","+blue+")");
  11.     var textNode = document.createTextNode("a new text");
  12.     newText.appendChild(textNode);
  13.  
My code stops working when I call appendChild(). I have seen this working when the code is inside the SVG file. But due to restrictions on the system I am working in I have to put my code on a HTML that has the SVG on an EMBED tag.

On Firefox this would be quite simple using something like this:

Expand|Select|Wrap|Line Numbers
  1.     var text_el = svg_doc.getElementById('value');
  2.     text_el.textContent = 'something';
  3.  
But this construction does not work in IE. Nor it throws an error. Does anybody know of any similar way of dealing with SVG text IE?

Any help would be really appreciated,

Thanks a lot in advance,

Regards,

Igor
Aug 21 '10 #1
1 7967
gits
5,390 Expert Mod 4TB
you might try to set innerHTML instead of textContent ... which should work in all browsers.
Aug 22 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Patrick Gibbons | last post by:
What I would like to do is create header and footer information for my webpages which are created by calling from a referenced .js page . . . for example in Header.js: <script...
3
by: Fabian | last post by:
I have created a javascript to manipulate a text strong given to it. It works in all the situations I put it in. Now, I want to create a form based interface. Essentially, the use types in the text...
27
by: C Gillespie | last post by:
Dear All, Hopefully I have a simple problem. Basically, I just want to alter some text with JS. Here is some of my test code: <snip> <script type="text/javascript"> var tmp='a';
3
by: jack-e | last post by:
Hi, Senario: I'm retrieving some text from a database and when I display this text on my page I want the first paragraph to be a different color. Do I need to break up the values i.e. find...
10
by: korund | last post by:
We can use special characters ('\n') to add line breaks in text in JavaScript popup Alert boxes. there is also few additional special characters: \' single quote \" double quote \&...
4
by: =?Utf-8?B?SmltSGVhdmV5?= | last post by:
I have a web page which uses some javascript. It has a variable which contains text which I want to retrieve from a file. I have no real knowldege of javascript so I was looking for a way to get...
1
by: mmalloc | last post by:
I have the following code to move some text with javascript that works both on ie and ff. I can't make it XHTML compatble. If i remove the doctype info it will work. I'm sorry to bother with such...
3
by: RuthC | last post by:
How to create a warped text using javascript? Is it possible..? pls help me ...
5
by: neogazz | last post by:
I am trying to a pass "text sentence" from a JavaScript function into my XHTML program is this possible?? 3134 Please see attached attached JavaScript coding. The reason why I am trying to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.