Ali Qamsari
Ali Qamsari

Reputation: 103

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

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

Upvotes: 2

Views: 348

Answers (1)

Cagri D. Kaynar
Cagri D. Kaynar

Reputation: 348

You can update your element class via

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

Upvotes: 1

Related Questions