By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,610 Members | 1,923 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,610 IT Pros & Developers. It's quick & easy.

read css rule value from svg

P: 1

I would like to know how to read a value of a property in a css class from svg using javascript.

Specifically, I would like to retrieve the font-size of the text element in the following example.

This example includes two files: svg file, and a css file that the svg file refers to.


//*********************svg file*******************************
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" standalone="no"?>
  2. <?xml-stylesheet href="commonMap.css" type="text/css"?>
  3. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "">
  5. <svg id="mainMap" width="950" height="475" 
  6.      viewBox="-82.049332 -30.5758 0.667485000000013 0.471659000000002" 
  7.       xmlns:xlink="">
  9.     <script language="text/ecmascript"  >
  10.     <![CDATA[                                
  11.     ]]>
  12.   </script>
  13. <text x="="-81.9332 " y="-30.2758" 
  14.        class ="FreewayText" >
  15.     Hello, out there
  16.   </text>
  17. </svg>
//*******************end of svg file*************************

================================================== =
//*****************commonMap.css file***************************************
Expand|Select|Wrap|Line Numbers
  1. *.FreewayText
  2. {
  3.       text-anchor: middle;
  4.       font-family:Verdana;
  5.       font-size: 0.001;
  6.       color: black;
  7. }
//***************end of css file********************************
Oct 25 '07 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
Welcome to TSDN!

I have no real experience with svg, but should your text element not have an id?

If it does, you can try:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("text element id").fontSize
Oct 25 '07 #2

Post your reply

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