zhaokun
zhaokun

Reputation: 114

How to create html tag with arbitrary attribute?

I wan to create a html tag: <div ng-app></div>, I try to use document.createElement('div') to create the div tag, but I don't know how to add ng-app to the div tag.

The function element.setAttribute(key, value) doesn't fit my flavor here.

Upvotes: 0

Views: 50

Answers (1)

Tim Ackroyd
Tim Ackroyd

Reputation: 635

Just pass an empty string as the second parameter for setAttribute.

var div = document.getElementsByTagName('div')[0];
div.setAttribute('ng-app','');
<div>Testing</div>

Upvotes: 1

Related Questions