Click here to Skip to main content
15,921,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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());
Posted
Updated 29-Jul-16 1:39am

1 solution

 
Share this answer
 
Comments
Member 12659554 30-Jul-16 1:00am    
Thanks for the solution. But,Isn't there any inBuilt function avail in jquery?
I guess, no.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900