javascript : domElement.getComputedStyle()

 

javascript : domElement.getComputedStyle()


Target:

Applicable with any DOM Element.

  • getElementById
  • getElementsByTagName
  • getElementsByClassName
  • getElementsByName
  • querySelector
  • querySelectorAll
  • select
  • etc.

In case of DOM NodeList first Node Element is processed for getComputedStyle.


Description :

This extension method is exactly window.getComputedStyle(domElement). It return list of all style attribute applicable to that domElement.


Note: when list of element passed then it reutrn first element's style attribute list.


Syntax:

DOMElement.getComputedStyle()

DOMNodeList.getComputedStyle()

HTMLCollection.getComputedStyle()


Usase:

  1. document.getElementById('firstDiv').getComputedStyle()
    It return CSSStyleDeclaration { }
  2. document.querySelector('#firstDiv').getComputedStyle()
    It return CSSStyleDeclaration { }
  3. document.querySelectorAll('ul').getComputedStyle()
    It return CSSStyleDeclaration { }
  4. document.body.getComputedStyle().width
    It return "1366px"
  5. document.body.getComputedStyle().backgroundColor
    It return "rgb(50, 0, 235)"
  6. document.querySelectorAll('ul').getComputedStyle().width
    It return "231px"


Download MYJS.js

MyJs is a collection of java script extension methods that enhances the JavaScript objects, class object, DOM element, domElementsCollections, Date, String, Number and other data type. 

Include in you project landing page (master page) and it will extends your DOM and JavaScript Objects.

Comments

Popular posts from this blog

javascript : String.right

javascript : String.left

javascript : .nextAll()