2

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

Ali Qamsari
  • 93
  • 1
  • 10

1 Answers1

1

You can update your element class via

document.getElementById("myId").className = "app-class";
Cagri D. Kaynar
  • 348
  • 1
  • 10
  • The `class` attribute in sample code of question isn't important. I know attributes can be set by assigning string literal. But i want to set value with 'Text node' datatype instead of 'string' datatype – Ali Qamsari May 17 '21 at 19:42