Issue #957šŸ’¬ AnsweredOpened March 15, 2018by Coyote60 reactions

Add custom attributes (data-) to assets/images on Upload/Selection

Quick answerby Coyote6

Found a solution, but surely there is a better one than this: Thanks.

Read full answer below ↓

Question

Hi, I am trying my best to find the proper/best way to do this, but I need to attach two custom HTML5 data tags to an image once it is selected from the Assets manager. Like so: I was hoping to be able to attach it when adding assets. Since I couldn't get that to work, I tried adding them on the component update event, but doubt that is returning a value to update them after being added. So next I tried using the selector and jQuery to add the attributes on the component update event, but that did not work either. I also tried extending the image component, and selecting that via the add asse...

Answers (3)

Coyote6• March 16, 2018

Found a solution, but surely there is a better one than this: Thanks.

artf• March 17, 2018

Your solution only updates the element inside the canvas and not its model (so in your final code you'll not gonna see them). When you update the model its element in view is updated automatically, eg.

Coyote6• March 20, 2018

Thanks! Would there be a feature in the future to add attributes during asset import? Just curious.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.