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:29 2201browse

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

2, then set the style

3, introduce jQuery

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

var h = $('div').css('width'); 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