How can set value of type Text node for Attribute of html elements

330 Views Asked by At

according to Text element document in MDN Value of Attr Node Can be of type Text element.

The Text interface represents the textual content of Element or Attr.

But how can i set value of a DOM element attribute to Text object. Some things like this:

var elm = document.getElementById('myId')
elm.attributes['class'] = new Text('app-class')

In web api documents, value of Attr is string.

UPDATE:

I know attribute can be set by assigning string literal.But i want to set value with Text node datatype instead of string datatype

1

There are 1 best solutions below

1
Cagri D. Kaynar On

You can update your element class via

document.getElementById("myId").className = "app-class";