Skip to content

Instantly share code, notes, and snippets.

@nasitra
Created May 23, 2016 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasitra/e491438ec87c97daca7e149a0d233165 to your computer and use it in GitHub Desktop.
Save nasitra/e491438ec87c97daca7e149a0d233165 to your computer and use it in GitHub Desktop.
Access JavaScript function in SVG
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="container">
<object data="image.svg" type="image/svg+xml" style="pointer-events: none;">
</div>
<script>
document.getElementById('container').onclick = function() {
var object = document.querySelector('object');
object.contentDocument.fillRandomColor();
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment