I am trying to check if some attributes are attributes DOM HTML5
. The code moves the markup html
and saves on Set
. My idea is to identify the attributes in this example ng-controller
, ng-repeat
, ng-bind
because other attributes ( id
and class
) are attributes DOM HTML5
.
HTML
<div id="html-markup">
<div class="class-1" ng-controller="myController">
<table id="the-table">
<thead class="table-header" >
<th ng-repeat="(key, val) in myList[0] track by key">
{{ key }}
</th>
</thead>
<tbody class="table-body">
<tr ng-repeat="item in myList track by item.id">
<td ng-repeat="(key, value) in item">
<span ng-bind="value"></span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
Javascript
const element = document.getElementById("html-markup");
const allChildrensNodes = element.childNodes;
const allChildrensElements = element.getElementsByTagName("*");
const attributesArray = Array.from(allChildrensElements)
.reduce((set, child) => {
Array.from(child.attributes).forEach((attr) => {
set.add(attr.name)
});
return set;
}, new Set())
console.log(attributesArray);//Set(5) {"class", "ng-controller", "id", "ng-repeat", "ng-bind"}
Is there any hack or trick to test this?
a codepen
to play with this: https://codepen.io/gpincheiraa/pen/veWKOj?editors=1010
source
share