-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9-35. Getting Styles.js
More file actions
27 lines (20 loc) · 1003 Bytes
/
9-35. Getting Styles.js
File metadata and controls
27 lines (20 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Example code (Here i am not uploading HTML and CSS file to Github of this code)
/* Get Element Styles values using JavaScript :
There are two ways we can get Element style value:
var selectElement = getElementById('selector')/querySelector('selector')
INLINE STYLES :
Syntax : selectedElement.style.{inline-style-property};
For example : selectElement.style.width
CSS FILE :
Syntax : window.getComputedStyle(selectElement).{style-property-name}
For example : window.getComputedStyle(selectedElement).width*/
console.clear()
var btnIncreaseFont = document.getElementById('btn-increase');
console.log(window.getComputedStyle(btnIncreaseFont).marginRight)
console.log(btnIncreaseFont.style);
var initialFontSize = window.getComputedStyle(mainHeading).fontSize;
initialFontSize = parseInt(initialFontSize.substr(0, (initialFontSize.length - 2)));
btnIncreaseFont.onclick = function() {
initialFontSize += 10
mainHeading.style.fontSize = initialFontSize + "px";
}