Ответ:
Используйте метод getComputedStyle
Window
.
getComputedStyle(document.body).direction;
getComputedStyle(document.body)["writing-mode"];
Почему?
В отличие от простого доступаstyle
объект узла, который может вернуть пустую строку по умолчанию (ae direction
по умолчанию равен "ltr", но вернет ""), getComputedStyle будет возвращать значение стиля, запрашиваемое каждый развремя, включая значения по умолчанию.
Пример:
let direction = getComputedStyle(document.body).direction;
let writing_mode = getComputedStyle(document.body)["writing-mode"];
console.log(direction, writing_mode);
В сторону:
Может также использоваться в комбинации с Назначение деструктуры :
let {direction, "writing-mode": writing_mode} = getComputedStyle(document.body);
let {direction, "writing-mode": writing_mode} = getComputedStyle(document.body);
console.log(direction, writing_mode);