javascript - IE 8 width issue with decimal values -


i have used 2 div element. below structure have used.

<div id="firstelement" style="width:681px; height:401px">       <div id="secondelement" style="width:50%;height:50%;"></div> </div> 

i need exact width("340.5px") of second div in ie8. how can using javascript?

tried below

$("#getwidth").click(function(){   var ele = document.getelementbyid("secondelement");     var box = ele.getboundingclientrect();     alert("width = "+ box.right - box.left); // integer value returned. }); 

can please give suggestion resolve issue?

try this:

var rect = $("#secondelement")[0].getboundingclientrect();  var width; if (rect.width) {   // `width` available ie9+   width = rect.width;   alert(width) } else {   // calculate width ie8 , below   width = rect.right - rect.left;   alert(width) } 

demo: http://jsfiddle.net/ishandemon/7s6lta50/


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -