如何使用jquery获得我在CSS类中给出的百分比宽度百分比

问题描述:

嗨..我有一个css类是.xyz。在这个类中,我有%的设置宽度属性。所以我的代码是

.xyz {width:3%}

我想要使用jquery的百分比相同的宽度。我到目前为止尝试了以下方法。 />
有没有什么方法可以直接获得我设置的相同宽度。



让我更清楚输出:我想要输出宽度为3%。



我尝试过:



1.

var f1 = $(。xyz)。width()/ $('。xyz')。parent()。width()* 100;

提醒(f1);



但是我得到输出宽度4.179797.

2.

alert($(。xyz)。css('width'));



我得到的输出是像素(px)

3.

alert($(。xyz)。width());

Hi.. I have one css class which is ".xyz" . In this class i have setup width property in "%". So my code is
.xyz {width:3%}
I want the same width which is in percentage using jquery.I have tried following ways so far.
Is there any way by which i can directly get the same width which i have setup.

Let me be more clear about output: I want width in output which is 3%.

What I have tried:

1.
var f1 = $(".xyz").width() / $('.xyz').parent().width() * 100;
alert(f1);

But by this i am getting output width 4.179797.
2.
alert($(".xyz").css('width'));

Output i got is in pixel("px")
3.
alert($(".xyz").width());

(。 xyz)。width()/
(".xyz").width() /


('。xyz')。parent()。width()* 100;

alert(f1);



但是我得到输出宽度4.179797.

2.

ale rt(
('.xyz').parent().width() * 100;
alert(f1);

But by this i am getting output width 4.179797.
2.
alert(


(。xyz)。css('width'));



我得到的输出是像素(px)

3.

alert(
(".xyz").css('width'));

Output i got is in pixel("px")
3.
alert(