Is it a bad practice to add extra attributes to HTML elements?

后端 未结 6 492
日久生厌
日久生厌 2021-01-04 01:30

Sometimes I add an attribute to some of my controls. Like:

Chris Sharma

I know it

6条回答
  •  -上瘾入骨i
    2021-01-04 01:51

    Yes. It is considered a bad practice. Your HTML (if it's 4.0) won't validate successfully. Instead, add a class like so:

    ...
    

    Remember that you can have multiple classes:

    ...
    

    And you can use CSS or JQuery to select out stuff based on these classes, and selectively override style based on the combinations:

    a.climber             { color: brown; }
    a.climber.girl        { color: red; }
    a.climber.girl.pretty { color: pink; }
    

提交回复
热议问题