简体   繁体   中英

how to detect percent width in css file with jquery

I want get width from css file with jquery but when use this method :

$('element').width() OR $('element').css('width'); get pixel size element but in css file this element has percent size ....

how to get it. html :

<div id="content"></div>

css

#content{width:50%}

For the sake of being bored:

var mywidth = $('#content').width(),
    parentwidth = $('#content').parent().width(),
    percentagewidth = (mywidth*100)/parentwidth;
    alert(precentagewidth+"%");

==Rounding the number==

Math.round(precentagewidth)

Math.round() documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM