Get between lines in js and jquery.

Source: Internet
Author: User

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!

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.