Consider following code snippets:

<div style="border:1px solid black;
  margin:20px;
  padding:10px;
  width:100px;
">
  Something
</div>    

<script>
  $elem = $('div');
  $elem = $elem.outerWidth(true)
     + $elem.innerWidth()
     - $elem.outerWidth()
     - $elem.width();
  alert($elem);        
</script>
What will be displayed in alert box?
Explanation

$elem.outerWidth(true) = 100+2*10+2*20+2*1 = 162
$elem.innerWidth() = 100+2*10 = 120
$elem.outerWidth() = 100+2*10 +2*1 = 122
$elem.width() = 100

The result is 60.000000000000014 Type conversion error?

2017 Jun 8, 12:44:28 PM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes