Is there a way to check if the html attribute is not part of the HTML5 DOM?

I am trying to check if some attributes are attributes DOM HTML5. The code moves the markup htmland saves on Set. My idea is to identify the attributes in this example ng-controller, ng-repeat, ng-bindbecause other attributes ( idand 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) => {
                //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 any hack or trick to test this?

a codepento play with this: https://codepen.io/gpincheiraa/pen/veWKOj?editors=1010

+4
source share
2 answers

Hey. If you want to start collecting with "ng-", you can add insted` code below

if(attr.name.startsWith('ng-'))
  set.add(attr.name)

( HTML-)

    const fullAttributeList = ['class','name','id',.....];
   ..
   ..
   ..
    if(fullAttributeList.indexOf(attr.name) ===-1)
      set.add(attr.name)
+1

, . ( , , ) spec. , , A) , B) , ; C) , , ( - , , value value, ; defaultValue).

+2

Source: https://habr.com/ru/post/1686889/


All Articles