Skip to content

Instantly share code, notes, and snippets.

@donquixote
Last active December 13, 2019 01:59
Show Gist options
  • Select an option

  • Save donquixote/f228ad928f00cb465230e47be30bd146 to your computer and use it in GitHub Desktop.

Select an option

Save donquixote/f228ad928f00cb465230e47be30bd146 to your computer and use it in GitHub Desktop.

Revisions

  1. donquixote revised this gist Dec 13, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions getComputedStyle.html
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <!DOCTYPE html>
    <html>
    <head>
    <style>
  2. donquixote created this gist Dec 13, 2019.
    28 changes: 28 additions & 0 deletions getComputedStyle.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    <html>
    <head>
    <style>
    div {
    --varname: '5';
    unknown_property: '5';
    content: 'hello';
    float: left;
    }
    </style>
    <script>
    var div = document.getElementsByTagName('div')[0];
    var style = window.getComputedStyle(div);
    var keys = ['--varname', 'unknown_property', 'content', 'float'];
    var values = {};
    for (var i in keys) {
    k = keys[i];
    values[k] = style.getPropertyValue(k);
    }

    console.log(values);
    div.innerHTML = JSON.stringify(values);
    </script>
    </head>
    <body>
    <div>hello w</div>
    </body>
    </html>