Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,18 @@ addEventListener("trix-attachment-add", (event) => {
})
```

You can also set image-specific attributes in the same handler. For example, set an attachment's `alt` text with `setAttributes`:

```js
addEventListener("trix-attachment-add", (event) => {
if (event.attachment.file instanceof File) {
event.attachment.setAttributes({ alt: "A friendly description of the image" })
}
})
```

`figcaption` content is edited through the attachment `caption`, but it does not automatically become the image's `alt` text. If you need both, set them explicitly.

# Editing Text Programmatically

You can manipulate a Trix editor programmatically through the `Trix.Editor` interface, available on each `<trix-editor>` element through its `editor` property.
Expand Down