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

1 Answer 1

1

You can update your element class via

document.getElementById("myId").className = "app-class";
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.