Is there an easy way to categorize the content of an HTML element?

HTML elements refer to content content . For my task, I have to make sure that I do not host interactive content sites.

I can currently traverse node parents to make sure none of them are of type <a>, <button>, <details>, <embed>, <iframe>, <keygen>, <label>, <select>, and <textarea> . All of these elements are part of the Interactive Content category.

Other types may also be interactive.

  • <audio> if a control attribute is present
  • <img> if usemap attribute is present
  • <input> if the type attribute is not in a hidden state
  • <menu> if the type attribute is in the toolbar state
  • <object> if usemap attribute is present
  • <video> if a control attribute is present

In addition, any element with the tabindex attribute is considered interactive .

These rules are part of the HTML specification and are well documented, but the kind of pain that needs to be tracked. Is there an easier way to check which categories of content an item belongs to?

+5
source share
1 answer

No, there is nothing in the DOM to classify elements in this way. Classifications were made only in the HTML5 specification. There are several old classifications that are reflected in the DOM, such as classifying form fields by type, with the type property, and you can indirectly find some classifications according to the rendering rules in the sense that different elements have different values. display value of the property in the settings style. But all of these modern classifications must be implemented in your code using element name lists. You can see this by carefully examining the DOM definitions in HTML5 and finding out that they do not cover classifications.

+4
source

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


All Articles