Reputation: 9425
I have an HTML page with external JavaScript module
<script type="text/javascript" src="js/js.js"></script>
and an external SVG map "img/map.svg".
I need to make clickable objects on the map which will in turn call some global JavaScript function myJSFunction
defined in "js/js.js". This function will modify the title and contents of the HTML page, hide the SVG map and display a table with some data instead. How can I do this? A naive attempt to set an onclick
event in the svg code like the following:
<g
id="g170"
onclick="myJSFunction()">
results in error:
Uncaught ReferenceError: myJSFunction is not defined at SVGGElement.onclick
Upvotes: 0
Views: 203
Reputation: 123985
You can access parent javascript functions via window.parent i.e. window.parent.myJSFunction()
Upvotes: 2