Issue #3171πŸ’¬ AnsweredOpened December 7, 2020by skbhagat400 reactions

Adding / Updating href trait does not add `<a></a>` wrapper to image.

Quick answerby skbhagat40

It's not working, even if I do `selectedElement.getTrait('href').set({value: 'fb.com', target: '_blank'})

Read full answer below ↓

Question

Expected Behavior - when I update href trait value, the image should be wrapped inside a with href value set. i.e. <a href="google.com"><img src="/></a> Current behavior = no change is reflected Here's code for adding trait The above function is triggered on double click, Please help me how do I add href to image dynamically from code without using trait manager. ```

Answers (4)

skbhagat40β€’ December 7, 2020

It's not working, even if I do `selectedElement.getTrait('href').set({value: 'fb.com', target: '_blank'})

skbhagat40β€’ December 8, 2020

I think the component view is not getting updated, if I repeat the action, it is rendering a tag with previous value.

skbhagat40β€’ December 9, 2020

It works if I update href in the attributes

GJSBlockβ€’ May 17, 2026

Thanks for reporting this, @skbhagat40. Great question about Adding / Updating href trait does not add <a></a> wrapper to image.. The recommended approach with Components is to use the event-driven API. Start here: Check the GrapesJS documentation for your specific module Look for the on() event li...

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.