question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with 'onclick' on SVG elements

See original GitHub issue

I’m building an SPA that shall make extensive use of SVG. This far I have not been able to get any form of ‘onclick’ working on my SVG elements. I have tried both $onclick="test" and onclick={e => this.run("test", e)}, in elements like these:

<circle cx={cx} cy={cy} r={rad} $onclick="test"/>
<rect x="8" y="8" width="90" height="90" stroke="blue" onclick={e => this.run("test", e)}/>

This, however, works fine: <h1 onclick={e => this.run("test", e)}>TEST</h1> I’m using apprun 2.23.12. Is this a bug?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
yysuncommented, Apr 14, 2020

It is now fixed in v2.23.13. I also added it as an example in the playground. https://apprun.js.org/#play/23

1reaction
yysuncommented, Apr 13, 2020

I see. Then it appears to be a bug. Will fix it.

On Mon, Apr 13, 2020 at 4:16 PM Jon Kleiser notifications@github.com wrote:

You can try with this, e.g. inside the SPA’s ContactComponent:

<svg viewBox="0 0 520 520" xmlns="http://www.w3.org/2000/svg"> <rect x="10" y="10" width="90" height="40" onclick={e => this.run("test", e)}/> <rect x="10" y="80" width="90" height="40" onclick="alert('You have clicked the rect.')"/> </svg>

and then this:

update = { “test”: (state, evt) => { console.log(“test: %s”, evt.target); return state; } }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/yysun/apprun/issues/94#issuecomment-613076774, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABJUM7LDS6OJXJMERQ5SZTRMNXK5ANCNFSM4MG7ROSA .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making an svg image object clickable with onclick, avoiding ...
Click on SVG's <g> element in <object> with click event. Works 100% ...
Read more >
onclick - SVG: Scalable Vector Graphics - MDN Web Docs
The onclick attribute specifies some script to run when the element is clicked. You can use this attribute with the following SVG elements:....
Read more >
SVG with OnClick JS Function Calls - YouTube
Lets create a quick SVG with the free online Method Draw editor, ... add in a few Javascript functions that are called when...
Read more >
HTML : Add onclick event to SVG element - YouTube
HTML : Add onclick event to SVG element [ Gift : Animated Search Engine ... If there any issues, contact us on -...
Read more >
SVG - Interactivity - Tutorialspoint
SVG elements support mouse events, keyboard events. We've used onClick event to call a javascript functions. In javascript functions, document represents SVG ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found