0

I'm trying to get Mouse X,Y and set them to my.css file's customvalue

:root{
--mouse-x:0px;
}

in ejs file, it load css file <link ~ my.css id="mcss"> and

<script>
var el = document.getElementByID('mcss');
<--Get Mouse X, save to var x-->
el.style.setProperty('--mouse-x',x+"px");
</script>

But It doesn't works well When I tried with document.stylesheets[0].rules[0] it works well. What's the difference?

이현욱
  • 21
  • 1
  • 4
  • 1
    There is no `document.getElementByID`. Did you mean [`document.getElementById`](https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById)? – Sebastian Simon Jul 28 '18 at 10:43
  • 1
    you are setting a property to a `` element which is not logical – Temani Afif Jul 28 '18 at 10:43
  • This might be helpful on how to find custom attributes: https://stackoverflow.com/questions/45763121/list-css-custom-properties-css-variables/45763800#45763800 – Asons Jul 28 '18 at 10:47
  • Single line script comments are marked by `//` not HTML delimiters. – RobG Jul 28 '18 at 11:15

0 Answers0