Questions tagged [getcomputedstyle]
98 questions
46
votes
10 answers
JS: Failed to execute 'getComputedStyle' on 'Window': parameter is not of type 'Element'
In short: I am trying to understand the meaning of this TypeError:
Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'
The error appears while lunching Mediawiki's VisualEditor, as can be seen…

OpenFox
- 511
- 1
- 4
- 8
16
votes
1 answer
getComputedStyle returns a CSSStyleDeclaration but all properties are empty on access
I have a simple div that uses a css class which in turn has a color and background-color property set.
var div = document.createElement("div");
div.classList.add("my-css-class");
container.appendChild(div);
//This prints out a CSSStyleDeclaration…

Clark
- 2,598
- 3
- 27
- 41
13
votes
2 answers
How to fix Window.getComputedStyle is not an object error
I am trying to use draggabilly available at
https://github.com/desandro/draggabilly
it works fine in html. Now when i have tried to add it in wordpress. I am getting following error in firebug console.
TypeError: Argument 1 of…

Nomi
- 710
- 3
- 11
- 21
12
votes
3 answers
getComputedStyle reporting different heights between Chrome/Safari/Firefox and IE11
This has been driving me a little batty all day and I haven't been able to find where anyone else has documented this discrepancy.
window.getComputedStyle(el).height
See http://jsfiddle.net/ZwF9H/6/ for the demo.
What I am expecting is that…

Geuis
- 41,122
- 56
- 157
- 219
11
votes
3 answers
How to get computed background color style inherited from parent element
I have this HTML page:
document.addEventListener("DOMContentLoaded", function (event) {
var inner_div = document.getElementById("innerDiv");
console.log(getComputedStyle(inner_div, null)["backgroundColor"]);
});
#outterDiv {
…

user4617883
- 1,277
- 1
- 11
- 21
8
votes
1 answer
window.getComputedStyle not working for shorthand properties in other browsers except Chrome
window.getComputedStyle give the style's value in Chrome, but in firefox and Microsoft Edge it gives an empty string and in Internet Explorer, it say that it doesn't support that method. Here is my code.
Whenever the Upvote image is clicked it fires…

Hemant Parihar
- 732
- 1
- 6
- 19
8
votes
1 answer
Using a jQuery clone outside the DOM
I've been working on a small project where I'm using the jQuery .clone() method.
Pitfall with this is using it on HTML that has unique identifiers.
So I went on implementing getComputedStyle to find the style properties of the original unique…

Shikkediel
- 5,195
- 16
- 45
- 77
7
votes
2 answers
getComputedStyle gives "transparent" instead of actual background color
This was a surprise. The following code does not seem to give me the actual colors on the screen:
h1 = document.querySelector("h1");
window.getComputedStyle(h1).color
Gives rgb(0, 0, 0) which I think is correct.…

Leo
- 4,136
- 6
- 48
- 72
5
votes
1 answer
Is color format specified in the spec for getComputedStyle?
I'm parsing a color string returned by getComputedStyle to get R, G, B, and A values from it.
So far (in Chrome and Firefox), color values always seem to come back in rgb or rgba format which is easy to parse:
const [, r, g, b, a] =…

Sandy Gifford
- 7,219
- 3
- 35
- 65
5
votes
2 answers
why are initial CSS styles not visible on DOM element.style field?
OK I have full expectation of going down in flames for asking something stupid (or at least duplicate), but in the attached snippet, why do I have to use window.getComputedStyle to access styles applied by CSS? I was under the impression that the…

Labrador
- 623
- 7
- 13
5
votes
5 answers
How to get actual CSS property value of an HTML element node?
As I understand the getComputedStyles() method, it should return an object that allows one to access the actual CSS property values of an HTML element node.
I created this simple example with a paragraph containing a span:
let span =…

Krisztián Balla
- 19,223
- 13
- 68
- 84
5
votes
1 answer
using getComputedStyle with jsdom
I fail to get the computed style value of color with jsdom:
require("jsdom").env({
html: '',
done: function(errors, window) {
console.log('color:…

Franck Freiburger
- 26,310
- 20
- 70
- 95
4
votes
2 answers
Get target style from Javascript while transitioning
During a transition, is there a way to see what the target value is for a style rule which is under transition? window.getComputedStyle gets the interpolated value, and element.style only looks at the style attribute (I think).
Here's a demo of the…

EoghanM
- 25,161
- 23
- 90
- 123
4
votes
2 answers
How to get in Javascript / jQuery only CSS override properties
I am trying to obtain the list of CSS properties of an element that are overridden, example:
.div{
position:absolute;
top:10px;
}
When we use this code:
jQuery('.div').css('bottom');
I obtain:
bottom:-10px;
If I use get computed or…

Ignacio Correia
- 3,611
- 8
- 39
- 68
3
votes
0 answers
Is it possible to "getComputedStyle" of an element that is not in the browser DOM?
I have not been able to find information about whether it is possible to getComputedStyle of an element that is not in the browser DOM.
My testing suggests that elements not inserted in the browser DOM do not get a computed style.
var el =…

user1283776
- 19,640
- 49
- 136
- 276