2021-10-17 18:26:00 +02:00
|
|
|
---
|
|
|
|
title: attr()
|
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
```js
|
|
|
|
Snippet snippet.attr(
|
|
|
|
string name,
|
|
|
|
mixed value,
|
|
|
|
bool overwrite = false
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
2022-07-27 11:07:12 -07:00
|
|
|
This `Snippet.attr()` method calls [`Attributes.add()`](/reference/api/attributes/add) under the hood,
|
2021-08-25 16:09:31 +02:00
|
|
|
but returns the Snippet object. This allows you to chain different calls together.
|
|
|
|
|
2022-07-27 11:07:12 -07:00
|
|
|
If the third parameter is set to `true` it will call [`Attributes.set()`](/reference/api/attributes/set) instead,
|
2021-08-25 16:09:31 +02:00
|
|
|
thereby overwriting the value of the attribute.
|
|
|
|
|
2022-01-19 11:31:39 +01:00
|
|
|
<Example part="snippet_attr">
|
|
|
|
An example of the Snippet.attr() method
|
|
|
|
</Example>
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
```js
|
|
|
|
let { Point, points, Snippet, snippets } = part.shorthand();
|
|
|
|
|
|
|
|
points.anchor = new Point(50, 15);
|
|
|
|
snippets.demo = new Snippet("logo", points.anchor)
|
|
|
|
.attr("data-scale", 0.8)
|
|
|
|
.attr("data-rotate", 180);
|
|
|
|
```
|