Home > Web Front-end > JS Tutorial > How to get attribute value without unit in jquery css

How to get attribute value without unit in jquery css

藏色散人
Release: 2020-12-17 16:36:40
Original
2311 people have browsed it

jquery css method to get attribute values ​​without units: first define a div; then set the style and introduce jQuery; then use the jquery css method to get the width of the element; finally use the parseInt method to remove the unit .

How to get attribute value without unit in jquery css

The operating environment of this tutorial: windows7 system, jquery1.10.0&&css3 version. This method is suitable for all brands of computers.

Recommended: "css video tutorial"

jquery css method to obtain attribute values ​​without units

1. First Define a div

<div></div>
Copy after login

2, then set the style

<style>
div {
    width: 100px;
    height: 100px;
}
</style>
Copy after login

3, introduce jQuery

<script src="path/to/jquery.min.js"></script>
Copy after login

4, use jquery’s css method to get the width of the element

var h = $(&#39;div&#39;).css(&#39;width&#39;);
console.log(h); //100px
Copy after login

5. The obtained value has a unit. Use the parseInt method to remove the unit.

var nopx = parseInt(h);
console.log(nopx);//100
Copy after login

The above is the detailed content of How to get attribute value without unit in jquery css. 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