Recently have been learning the knowledge of the Web, today in the practice of a JS instance, encountered a problem, JS take the element style, usually by Getelement.style to take, but this can only take the elements of the inline style, for writing in other places of CSS can do nothing, In a puzzled no result in the case, to check Baidu (encounter problems, I like to try to solve their own, the process of trying although not solve the problem, but at least know that there are N methods can not solve the problem).
On Sina Blog, see a predecessor wrote the blog, said Getelement.style is only to take the elements of the inline style, for not written in the element, can not be taken down, but, JS provides another way to easily remove the elements of the style object ( Document.getcomputedstyle (' Element object ', ' Pseudo-class name '). Attribute name), the desired style can be removed by means of the object-point attribute. Note that there are two parameters, one to fill in the element object we obtained, and another to fill in the pseudo class, if the element has no pseudo-class , the second property can be ignored without writing.
After reading, the confidence to come back to do their own exercises, the results of the problem has arisen, the same is no way to take the style attributes, tried for a long time, bored headache, helpless under, and back to help degrees Niang.
But the search for the article are very similar, said the method is similar, I wrote the wrong? and carefully check their own code, there is no problem! Where the hell is the problem?
Had to in Baidu on an article of Look, the sky is not negative, finally found an introduction getComputedStyle method article (that the original blog link can not find), which said a detail, getComputedStyle method, Not only can it be accessed through the document, but it can also be accessed through windows, is the problem here? immediately tried, haha, really suddenly solved the problem of a half-day. The specific principle, why use document to access the attribute, and through windows can? Now not quite understand, beginners, is working hard, the problem is left, and later with the deepening of learning, and then to solve the mystery.
The problem of the element outer chain style attribute of JS take