Home >Web Front-end >JS Tutorial >js basic improvement learning to operate DOM object style
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
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
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!