Skip to content

Dom.SetAttribute

boxgaming edited this page Jul 12, 2026 · 2 revisions

Sets the value of an HTML DOM element's attribute by name.
Available in release 0.11.0

Syntax

Dom.SetAttribute e, attributeName, attributeValue

Parameters

  • The e parameter specifies the DOM element on which the operation will be applied.
  • The attributeName parameter specifies the name of the attribute which will be set.
  • The attributeName parameter specifies the new value for the attribute.

Examples

Example 1: Set DOM element attribute values

Import Dom From "lib/web/dom.bas"

Dim As Object div, img
div = Dom.Create("div")
div.innerHTML = "<img id='test-image' src='logo.png' height='300' width='400' data-payload='test data'>"

img = Dom.Get("test-image")

Dim As Object attr
Dom.SetAttribute img, "height", "350"
Dom.SetAttribute img, "data-payload", "new data value"

Print Dom.GetAttribute(img, "data-payload")

Output

new data value

See Also

Dom.GetAttribute
Dom.GetAttributeNames
JavaScript element.setAttribute()

Clone this wiki locally