<svg
id="exampleSVG"
width="200"
height="200"
xmlns="http://www.w3.org/2000/svg">
<circle id="circle1" cx="100" cy="100" r="50" fill="blue" />
</svg>
<button id="setTimeButton">Set Current Time</button>
<p id="currentTimeDisplay"></p>SVGSVGElement: setCurrentTime() method / notebook
SVGSVGElement: setCurrentTime() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const svgElement = document.getElementById("exampleSVG");
const setTimeButton = document.getElementById("setTimeButton");
const currentTimeDisplay = document.getElementById("currentTimeDisplay");
setTimeButton.addEventListener("click", () => {
// Setting the time to 5 seconds
svgElement.setCurrentTime(5);
const currentTime = svgElement.getCurrentTime();
currentTimeDisplay.textContent = `Current time in the SVG: ${currentTime} seconds`;
});