Can I add a custom attribute to an HTML tag?

后端 未结 17 2644
醉话见心
醉话见心 2020-11-22 08:06

Can I add a custom attribute to an HTML tag like the following?


17条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 08:35

    well! you can actually create a bunch of custom HTML attributes by disguising the data attributes in what you actually want.

    eg.

    [attribute='value']{
    color:red;
    }
    
    hello world
    

    It apparently works but that would invalidate your document, there is no need of using JScript for you to have custom attributes or even elements unless you have to, you just need to treat your new formulated(custom) attributes just the same way you treat your "data" attribute

    Remember "invalid" does not mean anything. The document will load fine at all the time. and some browsers would actually validate your document only by the presence of DOCTYPE....., you actually know what I mean.

提交回复
热议问题