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

How to get attribute value without unit in jquery css

藏色散人
藏色散人Original
2020-12-16 10:26:292204browse

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>

2, then set the style

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

3, introduce jQuery

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

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

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

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

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!

Statement:
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