Home > Web Front-end > JS Tutorial > JavaScript reads styles outside of inline (introduction to the differences between style, currentStyle, and getComputedStyle)_javascript skills

JavaScript reads styles outside of inline (introduction to the differences between style, currentStyle, and getComputedStyle)_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 18:27:57
Original
1098 people have browsed it

There are three ways of style sheets
Inline Style: It is written in the Tag. Inline Style is only valid for all Tags.
Internal Style Sheet: It is written in the of HTML. The internal style is only valid for the web page where it is located.
External Style Sheet: If many web pages need to use the same styles (Styles), write the styles (Styles) in a CSS file with the suffix .css, and then use it on each page This CSS file is referenced in the web pages of these styles.

The following is js for reading styles other than inline styles. It can only be read but not written.

Copy code The code is as follows:

var mydiv = document.getElementById('mydiv');
if(mydiv.currentStyle) {
var width = mydiv.currentStyle['width'];
alert('ie:' width);
} else if(window.getComputedStyle) {
var width = window.getComputedStyle(mydiv, null)['width']
alert('firefox:' width);
}
In addition, under FF, you can also obtain it through the following method
document.defaultView.getComputedStyle(mydiv,null).width
window.getComputedStyle(mydiv , null).width


Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template