I am trying to use a javascript function (which is in a separate js file) for my onclick
event for a svg component. I have tried referencing the file from within my svg node, but I get an error saying function undefined
. It does say that the src attribute within the script tag is not declared.
I tried changing the scr
to xlink:href
and adding the xmls:xlink
attribute to the svg but I get the same problem.
If I add the function within the svg node it works fine.
How and where do I reference the js file with the function that I want to call?
This is the contents of my SVG file. The method I want to call is ShowContextMenu() which is in another file.
<svg class="SystemOverview" id="m" currentScale="1" xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 900 500">
<svg class="p21" componentType="Valve2Way" onclick="ShowContextMenu()">
<line x1="73" y1="40" x2="73" y2="45" stroke = "black"></line>
<line x1="73" y1="62" x2="73" y2="66" stroke = "black"></line>
<polygon id="p21IN" points="65,43 73,53 80,43" stroke="black" fill="white"></polygon>
<polygon id="p21OUT" points="65,62 73,53 80,62" stroke="black" fill="white"></polygon>
<polygon id="p21ALERT" points="60,40 85,40 85,66 60,66" stroke="none" stroke-width="2" fill="none"></polygon>
</svg>