# SVG Elements Mouse Clicked

**URL:** <https://forum.inductiveautomation.com/t/svg-elements-mouse-clicked/56528>\
**Category:** Ignition\
**Created:** [February 24, 2022, 6:23pm UTC](https://forum.inductiveautomation.com/t/svg-elements-mouse-clicked/56528 "2022-02-24T18:23:02Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [February 24, 2022, 6:23pm UTC](https://forum.inductiveautomation.com/t/svg-elements-mouse-clicked/56528/1 "2022-02-24T18:23:02Z")

</div>

Hello All,

I am trying to click on SVG elements to change their colors for pass/fail and add notes. Something like this thread:

> [@Using event bubbling effect to pass click event to underneath object in perspective](https://forum.inductiveautomation.com/t/using-event-bubbling-effect-to-pass-click-event-to-underneath-object-in-perspective/51297):
>
> Hello, Right now the perspective doesn’t support SVG click event to passes the name of the selected element. I try to have this simply by adding some transparent label underneath each element and assign of event click script for my requirement. I put the label underneath SVG because I want to use the CSS hover effect for each element. As of 8.1, we have some options called stop propagation. If I uncheck this option, the click event of SVG should pass to the underneath object but it doesn’t w…

With a responsive design, it is not possible to use the coordinates of those elements as they will be changed by screen sizes. Is there any way that I can click on each element and know which element I clicked on?

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/2/e2ef4c36e6f2fdbfb5b219824acadc06bb78efb3.png)

---

<div class="post-metadata">

**Author:** ![Adriaan.leRoux](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@Adriaan.leRoux](https://forum.inductiveautomation.com/u/Adriaan.leRoux)\
**Post date:** [February 24, 2022, 6:36pm UTC](https://forum.inductiveautomation.com/t/svg-elements-mouse-clicked/56528/2 "2022-02-24T18:36:04Z")

</div>

Can you not have this SVG element be an icon or image perhaps? I have clickable icons which works fine for me

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [February 24, 2022, 7:27pm UTC](https://forum.inductiveautomation.com/t/svg-elements-mouse-clicked/56528/3 "2022-02-24T19:27:03Z")

</div>

The thing is the SVG file is big with so many details on it and it makes it really hard to have each element as an icon.

---

<div class="post-metadata">

**Author:** ![Steve\_Laubach](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steve_laubach/32/60900_2.png) [@Steve\_Laubach](https://forum.inductiveautomation.com/u/Steve_Laubach)\
**Post date:** [February 24, 2022, 8:10pm UTC](https://forum.inductiveautomation.com/t/svg-elements-mouse-clicked/56528/4 "2022-02-24T20:10:53Z")

</div>

Maybe you’re talking about functionality that wasn’t in perspective when I last did custom SVG stuff in Perspective. I put an SVG in Image management and loaded it into an image control.

From there you can use the “Tint/Color” property to color it. That might not be the functionality you’re looking for because it will color the entire SVG but I thought I’d mention it in case it is helpful.

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [February 24, 2022, 8:14pm UTC](https://forum.inductiveautomation.com/t/svg-elements-mouse-clicked/56528/5 "2022-02-24T20:14:38Z")

</div>

Thank you! Well, I actually imported the SVG as an embedded image to get the individual elements; however, I want to be able to click on each individual element using mouse click event and then change its color.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 24, 2022, 8:44pm UTC](https://forum.inductiveautomation.com/t/svg-elements-mouse-clicked/56528/6 "2022-02-24T20:44:11Z")

</div>

There is currently no way to respond to click events at the element level. You could potentially, with a whole lot of work, use the click event of the entire SVG, but that is far from trivial.

If you need to respond at this level, then you should split the SVG up into smaller components. Which depending on the number of components could become a performance issue.

One potential solution would be to have the SVG in a coordinate container set to percent mode. Then place an Icon (or other lightweight component) with an empty path effectively making it transparent on top of the areas where you need to respond to a click event. Make sure you set the coordinate container to maintain the Aspect Ratio.

Then you can respond to click events on the icon and modify the elements as needed.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [February 25, 2022, 8:44am UTC](https://forum.inductiveautomation.com/t/svg-elements-mouse-clicked/56528/7 "2022-02-25T08:44:31Z")

</div>

It is perspective right? You kinda need acces to javascript for this to make work…

I ended up making a perspective module for nader which can read out the names (ids) of the svg elements.  
Allowing you to use it to trigger events.

If you are interested in some more info about the module and price, feel free to send me a private message.

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [February 25, 2022, 1:12pm UTC](https://forum.inductiveautomation.com/t/svg-elements-mouse-clicked/56528/8 "2022-02-25T13:12:18Z")

</div>

Thank you very much for the information. I guess I have to use that transparent icon method then, the problem with that is for each element you need to create one icon.

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [February 25, 2022, 1:12pm UTC](https://forum.inductiveautomation.com/t/svg-elements-mouse-clicked/56528/9 "2022-02-25T13:12:41Z")

</div>

Yes, it is. Thank you very much, Victor. That would really help me.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 3, 2022, 3:16pm UTC](https://forum.inductiveautomation.com/t/svg-elements-mouse-clicked/56528/10 "2022-11-03T15:16:01Z")

</div>

Made something new for 8.1.22

> [@Javascript inject in Perspective... have fun](https://forum.inductiveautomation.com/t/javascript-inject-in-perspective-have-fun/65805/5):
>
> Gonna try to keep this topic updated with all my cool injectings stuck_out_tongue Version 8.1.22 svg clicker wink[https://forum.inductiveautomation.com/t/new-feature-perspective-piping/49919/138?u=victordcq](https://forum.inductiveautomation.com/t/new-feature-perspective-piping/49919/138)
