Can I use non existing CSS classes?

后端 未结 13 1987
北荒
北荒 2020-11-27 12:54

I have a table where I show/hide a full column by jQuery via a CSS class that doesn\'t exist:

13条回答
  •  野性不改
    2020-11-27 13:43

    According to HTML5 specification:

    A class attribute must have a value that is a set of space-separated tokens representing the various classes that the element belongs to. ... There are no additional restrictions on the tokens authors can use in the class attribute, but authors are encouraged to use values that describe the nature of the content, rather than values that describe the desired presentation of the content.

    Also, in the version 4:

    The class attribute has several roles in HTML:

    • As a style sheet selector (when an author wishes to assign style information to a set of elements).
    • For general purpose processing by user agents.

    Your use case falls under the second scenario, which makes it a legitimate example of using a class attribute.

提交回复
热议问题