Skip to main content
100%

Adding links to objects in v7

✓ Published0🌍 Public
Dd3noob
Last edited Jun 19, 2021
Created on Jun 19, 2021

This example shows how to add a hyperlink to an SVG rectangle and make text clickable through it. The code uses d3.v7 to append an anchor element with an `xlink:href` attribute pointing to a Wikipedia page, then adds the rectangle inside the anchor. A separate text element displaying “gongoozler” is positioned over the rectangle and given `style("pointer-events", "none")` so clicks pass through to the linked shape beneath. The SVG is rendered directly in the browser with a lightgreen rounded rectangle.

AI-generated description

The above example is intended to demonstrate adding a hyperlink to an object (the rectangle) and instructing the text object to be transparent to the pointer so that the link on the rectangle is recognised 'through' the text.

This is one of the code samples for the update to the book D3 Tips and Tricks to version 7 of d3.js.

mit Licensed

Similar vizzes