The problem of the element outer chain style attribute of JS take

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.