Home > Web Front-end > JS Tutorial > body text

js basic improvement learning to operate DOM object style

php中世界最好的语言
Release: 2018-06-04 14:15:31
Original
1393 people have browsed it

This time I will bring you the basics of js to improve the learning of operating DOM object styles. What are the precautions for operating DOM object styles in js? The following is a practical case, let's take a look.

A simple example:

We will find that xx.style.xx can only obtain inline styles, but width cannot be obtained (inline styles mean that external links cannot be modified. style)

What cannot be obtained is that we have not set the width. It is impossible to obtain it. We clearly know that it is 100%, but this operation cannot go out of bounds

js basic improvement learning to operate DOM object style

Addition and subtraction of pixels:

Convert with parseInt, add it, and finally restore it back

Expansion: Use W3C getComputedStyle (style tag). Style name

Advantages: All label styles can be obtained

Defects: There is compatibility, IE9 and above versions can use this format

js basic improvement learning to operate DOM object style

IE8 and previous versions can use this format :Tag.currentStyle.height

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Basic data types for js basic improvement learning

JS concept questions summary and answers

The above is the detailed content of js basic improvement learning to operate DOM object style. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!