Skip to content

Set HTML attribute

Sets the HTML attribute of the target element to the specified value.

Set HTML attribute Action

In the example shown in the image above, the element gets the data attribute value set to open.

HTML preview

This action works on any element and any attribute.

Let's look at a few examples.

Set image

To display an image, you can set the src attribute of an image.

In the function editor, you would return the URL of the image:

js
(c, f, i, n, r, v, e, t) => {
  return 'https://example.com/image.png'; 
};

If you're rendering a list of images from a request, you can set the value like this:

js
(c, f, i, n, r, v, e, t) => {
  return r.get_products.data[v.i].product_image; 
};

See the render list action for more info.

If you want to set the URL of a link, you can set the href attribute of your link element:

js
(c, f, i, n, r, v, e, t) => {
  return '/some-page'; 
};

Disable input

To disable an input, add the disabled attribute to your input field.

Then return either true or false from the function editor.

js
(c, f, i, n, r, v, e, t) => {
  return true; 
};

Further reading

A lot of functionality can be accomplished with HTML attributes alone.

We highly encourage you to learn what's possible with HTML, especially HTML input attributes.