views:

84

answers:

1

i have a index.html file which includes svg and CSS file and 2 javascripts file and has a javascript function inside of it

for some reason i cannot get the javascript function to run.

is the strucutre supposed to be different>?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript Tooltip Demo</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<embed src="usmap.svg" width="3000" height="1000"
type="image/svg+xml"
pluginspage="http://www.adobe.com/svg/viewer/install/" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt; </script>
<script src="http://cdn.jquerytools.org/1.2.4/full/jquery.tools.min.js"&gt;&lt;/script&gt;
<script type="text/javascript">
    $(document).ready(function () {
        $(".addtooltip").tooltip();
    }); // closes document.ready
</script>
</body>
</html>
+2  A: 

Hi,

There are several reasons why the code you posted here will not work.

First, you're trying to query the DOM of the embedded SVG document, but the query being performed will only query the DOM on the current page. To access the DOM of an embedded SVG document, you will need to do something like the following:

http://stackoverflow.com/questions/2753732/how-to-access-svg-elements-with-javascript/3379830#3379830

The second reason why this will not work is that jquery is currently not able to query SVG documents. The reason for this is that the class attribute is encoded as an animated value in SVG DOM, as opposed to a string in HTML DOM, which confuses jquery.

For this reason, and because I believe it would fix the other problems you are having with respect to structuring your HTML document, I would recommend that you use the jQuery SVG javascript library: http://keith-wood.name/svg.html

This does many things that appear to be relevant to your project, including modifying jQuery so that it is able to query SVG documents, and embedding the SVG document in the HTML document using either native DOM, if it's supported, or the Adobe plugin. Be careful, though, as I have found the SVG DOM plugin to be unstable in certain situations in Chromium.

echo-flow