javascript - How to get width in percentage using jquery -
i trying value of width in percentage using j-query. don't want set value of in j-query.i had tried width() method , css('width').they both return not return result in percentage.
html-code
style.css
.demo{ width:50%; }
jquery code
$(document).ready(function(){ var = $('.demo').css('width');//50px var = $('.demo').width();//50 });
thanks in advance help.
$(function() { var parentwidth = $(document).width(); // parent element var demowidth = ($(".demo").width()/parentwidth * 100).tofixed() +"%"; });
this give width in %
Comments
Post a Comment