I'm trying to get body tag attribute value in JavaScript.
Here is body tag containing data-elementor-device-mode="tablet" attribute with value:
Here is the output when I call console.log in my browser console:
But when I write the same in my .js file I get null when call body.getAttribute('data-elementor-device-mode') or get undefined when call body.dataset.elementorDeviceMode.
Here is my code pieces:
const body = document.body
console.log(body.getAttribute('data-elementor-device-mode'))
const body = document.body
console.log(body.dataset.elementorDeviceMode)
Don't understand, what is problem. Can you help me please?