Questions tagged [getcomputedstyle]

80 questions
3
votes
1 answer

Will the CSSStyleDeclaration returned through getComputedStyle always have the same length for a given browser?

I'm looking to compare two Elements to find all differences in their computed styles. In order to do this, I'm iterating over all styles of A, and comparing them to B by doing the following: var stylesA = window.getComputedStyle(a), stylesB =…
Ian Clark
  • 8,852
  • 4
  • 29
  • 47
3
votes
2 answers

Firefox getComputedStyle returning none computed value

I'm calling getComputedStyle on an element that defines left, right and bottom. In Chrome this returns 'auto' as the value for top but in Firefox this returns the pixel value, however if you look at the inspector in Firefox the top value doesn't…
DEfusion
  • 5,463
  • 5
  • 42
  • 59
3
votes
0 answers

GetBoundingClientRect doesn't work outside the window

I am making a script that should measure distances in a post. For example, if i have three posts: Post 1: two lines of text, then the image that I want to see. Post 2: Just the image that I want to see. Post 3: The image I want to see Followed by…
3
votes
1 answer

javascript getComputedStyle, but not inherited ones (in chrome)

I want to get only the computed styles of the elements on a page, without all the inherited styles var allElements = document.querySelectorAll( '*' ); for (var i=0;i
2
votes
0 answers

How to get alpha of background color in HTML?

The below feels a bit overengineered, is there a direct accessor? const bg = window.getComputedStyle(document.querySelector('.source')).backgroundColor document.querySelector('.result').innerHTML = bg.startsWith('rgba') ?…
Jamesgt
  • 453
  • 4
  • 14
2
votes
2 answers

How to get child property value of a element property using selenium webdriver, NUnit and C#

I am testing websites using selenium webdriver and I am having difficulties getting the value of a property that is a child of another property. For me, this 2nd/child level is always coming back as null. When trying to get a value of an upper…
GIZNAJ
  • 461
  • 3
  • 21
2
votes
0 answers

Why does .getComputedStyle() appear to be the only commonly used method to return the incorrect height of an element?

Question: Under certain circumstances .getComputedStyle() appears to return an incomplete/incorrect value for the height property of an element. Now I'm worried. Is it known to return unpredictable or incorrect values for other…
DR01D
  • 1,245
  • 9
  • 21
2
votes
0 answers

Javascript wait for all element styles to be applied

I have a need to resolve (i.e. 'apply', not just load into memory) all styles for all elements of a HTML webpage with some javascript/jquery. The styles may be in-line within the element's style tag, in-line within the page's styles, or external…
TerrorBight
  • 185
  • 1
  • 13
2
votes
3 answers

How to properly detect a change in computed style property with Angular 2?

I have created an Angular 2 app which contains a component whose HTML element I am trying to position relative to that of another component. In order to compute the exact coordinates, I need to know my own element's width and height as rendered by…
not2savvy
  • 1,037
  • 10
  • 22
2
votes
1 answer

getComputedStyle failed to execute

I have this simple bit of code: var recipes = document.getElementsByClassName("recipes"); var recipesStyle = window.getComputedStyle(recipes, null); It returns this error message: Uncaught TypeError: Failed to execute 'getComputedStyle' on…
user3669771
  • 55
  • 1
  • 1
  • 8
2
votes
0 answers

How to get the text content of a ::before pseudo-element?

In this example the ::before pseudo-element's content is not a static value, but a counter. I want to get the current value "2" instead of the general formula "counter(itemcounter)". // Expected value is 2 instead of…
Tamás Bolvári
  • 2,530
  • 3
  • 28
  • 49
2
votes
1 answer

getComputedStyle property values

I'm trying to report the value of my border radii of an oval div I created, but I'm getting an undefined value returned. Can anyone explain why? Am I making a simple mistake or is there something wrong with my code? Thank you!
afryingpan
  • 333
  • 4
  • 15
2
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
  • 21,662
  • 20
  • 60
  • 90
2
votes
1 answer

How to apply document CSS properties to a Parsed element without appending it to the DOM

The common way to do it is to appending the new element to the body and then get the computed css values like in this jQuery script: var $body = $('body'); var $this = $(this); var $text = $this.text(); if($text=='') $text =…
user2200481
2
votes
0 answers

How do I get computed styles from browser's dev tools?

I'm collecting all computed styles of an element with getComputedStyle. But it returns many unnecessary properties like 'animation-duration', 'direction', 'ime-mode', etc, yielding more than 200 properties total. Meanwhile browser's web dev toolbar…