# 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 gySVG('a')
and attach it to the SVG document with .attachTo()
.
More info: mdn (opens new window) | w3c (opens new window)
# .href()
a.href( url )
Set the URL or URL fragment the hyperlink points to.
argument:
{string} url
The URL to linkreturns:
{gySVGObject}
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} target
Some of this values: '_self' | '_parent' | '_top' | '_blank' | <window_name>returns:
{gySVGObject}
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} mimetype
A valid MIME Typereturns:
{gySVGObject}
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 | discard | 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.