Custom html tags — Is there a better way?

前端 未结 4 1243
迷失自我
迷失自我 2021-01-15 10:00

I am attempting to complete a browser plugin that will analyze text and mark it in some fashion.

Basically, let\'s say your browsing and you see this come across th

4条回答
  •  有刺的猬
    2021-01-15 10:29

    There’s really no guarantee that is never recognized as a tag with some special semantics or formatting. It might be improbable if you use a very messy tag name, but would you, really? People tend to use mnemonic names when they invent tags, and then there’s a real chance of clashing with tags in some current or future spec or browser.

    Moreover, some old versions of IE ignore unrecognized tags completely, e.g. do not let you style them. This can be avoided using document.createElement() once for each tag name, though.

    Using span or div is as such safe in practice. There is no reason to think that browsers have some fancy formatting for them by default. Just as we don’t stop using h1 even though it is theoretically possible that it will make the content pink and blinking. It’s impossible to be foolproof if you expect browser vendors to be totally crazy.

    Using classes is a different matter, though only in the sense that other style sheets play with the same class names as you. You might need to work in an environment where other author style sheets interfere with yours. But this just calls for caution; it does not make a span or div element with a class the wrong tool.

提交回复
热议问题