javascript - What repercussions do I get by using an undefined HTML element? -
in effort write more expressive html, feel custom html elements way webapp or document may write have meaning gleamed tag name without use of comments.
it appears can define custom html element with:
document.registerelement("x-el");
however appears can use custom element before defining it:
<body> <x-salamander>abc</x-salamander> </body>
or even:
<salamander>abc</salamander>
i suppose invalid html, both firefox , chromium proceed display element without problems or console warnings.
i can execute following no complaints browser:
document.getelementsbytagname("salamander")[0]
using tag name selector in css works fine. so, problems might face if use undeclared elements in way?
the problem you're trying not can tell break in expected ways. it's when deviate standards in way, no 1 knows what expect. is, definition, undefined, , behavior of browsers see undefined.
that said, might work great! here's things keep in mind:
- the htmlunknownelement interface you're invoking make work in supported way - far can tell in 5 minutes of searching, introduced in html5 spec, in html5 browsers use appropriately, no longer undefined scenario.
registerelement
comes play, can take htmlunknownelement , make known. - browsers typically @ coping unexpected markup... won't result in great things (see: quirks mode).
- not browsers created equal. chrome, firefox, safari, opera, ie have reliable way handle these elements reliably (even pre-html5)... have no idea screen reader (lynx) or various other esoteric, outdated, niche or future browsers it.
- everyone has said same thing, it's worth noting: fail validation. it's ok have validation errors on page long know , why there, , qualify, you'd better have reason.
browsers have long history of taking whatever give them , trying reasonable it, you're ok, , if interested in targeting html5 browsers, you're ok. html related, universal advice test target demographic.
Comments
Post a Comment