How to define support for a "scoped" style attribute

Is there a recommended test to determine if the user's browser supports the "scoped" attribute in style elements?

+4
source share
2 answers

I do not think there is a recommended test, but I just wrote it and I recommend it

var is_scoped = (function(s) {
    s.setAttribute('scoped', 'true');
    return !!s.scoped;
})(document.createElement('style'));

to be used as

if ( is_scoped ) {
    // scoped styles are supported
}

Fiddle

Currently, style areas are only supported in the latest Firefox.

It is written a little more verbose, it is easier to see what is happening

var style = document.createElement('style');
style.setAttribute('scoped', 'true');
var is_scoped = style.scoped === true;

scoped true.
, , , style.scope true , , undefined.

, scoped.

+6

.

var is_scoped = (function(s) {
    return 'scoped' in s;
})(document.createElement('style'));
+2

Source: https://habr.com/ru/post/1536684/


All Articles