Change width with jQuery.css () and em

I need to change the width of a div using jQuery.

When I use the following, it works:

$('#footer').css('width', '100%'); $('#footer').css('width', '-=239'); 

When I use this, it works:

 $('#footer').css('width', '100%'); $('#footer').css('width', '-=239px'); 

But when I use this, it does nothing:

 $('#footer').css('width', '100%'); $('#footer').css('width', '-=21em'); 

Is there a way to get jQuery to work with em ? or calculate em to px and set a variable, for example, and subtract this value?

edit: thanks to everyone for correcting my spelling and code!

+6
source share
1 answer

I tried and it works, I think you should check your code, I checked it in all browsers, and it works fine, and they both work fine, you can use this code by putting this code in a dummy page, and you can see it works

 <style> #footer{ background: black; height:50px; } </style> <script type="text/javascript"> $(function(){ $('#footer').css('width', '100%'); $('#footer').css('width', '-=210em'); }); </script> <div id="footer"></div> 
+1
source

All Articles