I've been trying to check if some attributes are not part of DOM HTML5
attributes. The code traverses the html
markup and save on a Set
. My idea is to identify in this example the attributes ng-controller
, ng-repeat
, ng-bind
because the other attributes (id
and class
) are part of DOM HTML5
attributes.
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) => {
//if(ATTRIBUTE IS NOT PART OF DOM HTML5 ATTRIBUTES)
set.add(attr.name)
});
return set;
}, new Set())
console.log(attributesArray);//Set(5) {"class", "ng-controller", "id", "ng-repeat", "ng-bind"}
Is there some hack or trick to check this?
a codepen
for play with this: https://codepen.io/gpincheiraa/pen/veWKOj?editors=1010