a
The a SVG element creates a hyperlink to other web pages, files, locations in the same page, email addresses, or any other URL. It is very similar to HTML’s a element.
SVG's a element is a container, which means you can create a link around text (like in HTML) but also around any shape.
Usually, this element is created with:
const a = parentElement.add('a')It's possible to create it as a disconnected element with gSVG('a') and attach it to the SVG document with .attachTo().
.href()
a.href( url )Set the URL or URL fragment the hyperlink points to.
argument:
{string} urlThe URL to linkreturns:
{gSVGObject}The original object
const url = element.href();Get the href current value.
- returns:
{string}The current URL
.target()
a.target( target )Set where to display the linked URL.
argument:
{string} targetSome of this values: '_self' | '_parent' | '_top' | '_blank' | <window_name>returns:
{gSVGObject}The original object
const target = element.target();Get the target current value.
- returns:
{string}Thetarget.
.type()
a.type( mimetype )Set a MIME type for the linked URL.
argument:
{string} mimetypeA valid MIME Typereturns:
{gSVGObject}The original object
const mimetype = element.type();Get the type current value.
returns:
{string}The mimetype valueParent elements: defs | g | marker | mask | pattern | svg | switch | symbol | text | textPath | tspan.
Child elements: animate | animateMotion | animateTransform | circle | clipPath | defs | desc | ellipse | filter | foreignObject | g | image | line | linearGradient | marker | mask | metadata | mpath | path | pattern | polygon | polyline | radialGradient | rect | set | stop | style | svg | switch | symbol | text | title | use | view.