Get between lines in js and jquery.
The style is divided into line style and line style. In general, the interline style is rarely used, because it has only one element in the scope of its function, rather than the range of the interline style can be a class of elements (that is, it has the same Germany label, or have the same class name (of course, the id name cannot be the same and is unique)
In js and jquery, how can we obtain the element style, such as width or height?
Js
1. Line Style:
I believe that everyone knows how to get the between-line style, whether it is reading a book or reading something, that is, using a style:
The style method can only be used to obtain the line style.
2. Non-interline Style
Here, I directly encapsulate the function and will not edit and run it in the editor.
Function getStyle (obj, attr) {if (obj. currentStyle) {return obj. currentStyle [attr];} else return getComputedStyle (obj, null) [attr]; // you can set false to the place where the null parameter is set. If one parameter is included, the value is arbitrary, happy. }
Well, we can encapsulate such a simple function. It will be okay to call it when getting non-interline elements. (Ps: for example, getStyle (oDiv, 'width '))
Jquery
In fact, I thought that jquery needs to use the function encapsulated in the same way as js; well, the result is not needed at all. Use the method directly.
The first is to use the width () and height () methods in jquery (these two methods obtain only the width and height of the content area, and the obtained data type is number), (ps: in addition, the outerWidth () and outerHeight () methods are used to obtain the width and height of the box model including the padding and border)
There is also a way to get a non-interline style, using the css () method, the Data Type obtained by this method is string
Grace, that's almost all. Over!
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!