Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
The below Jquery script doesnt work with IE 9 . Any idea why ?

It gets the max width of the label and aligns the textboxs in line on the form.This works great in Chrome and FF but not in IE9.


JavaScript
$(document).ready(function () {
           var max = 0
           $('div.align').each(function () {
               $(this).find('label').each(function () {
                   width = $(this).width()
                   if (width > max) {
                       max = width
                   }
               });
               $(this).find('label').width(max);
               max = 0
           });
       });
Posted
Comments
ZurdoDev 8-Mar-13 8:17am    
I know IE has always had issues with width. I can't remember off hand but it either includes borders or doesn't include borders in the width. Just put a breakpoint and see what the value is and you may have to put a condition in for IE.
spankyleo123 8-Mar-13 8:29am    
Thanks will try that.
Prasad Khandekar 8-Mar-13 8:41am    
Yes in quirks mode IE9's box model is different than the W3C box model. Thus in quirks mode IE width becomes content width + 2 * border-width + 2 * padding, Which is as per w3c model is the content width. Please see following article on Wikipedia. As a precaution you may want to output following meta tag so that IE 9 always uses Document Mode as IE 9 Standard & Browser Mode as IE 9.

<meta http-equiv="X-UA-Compatible" content="IE=Edge"></meta>

regards,
ZurdoDev 8-Mar-13 8:45am    
+5 on the details.
spankyleo123 8-Mar-13 9:33am    
Thanks I have added the meta tag. In my case IE in quirks mode executed the above jquery perfectly, but in IE9 Standard its doest work. I have stepped through the debugger and when it gets out of the loop. this line returns max=0, wonder why that is.?
<pre lang="Javascript">
$(this).find('label').width(max);
</pre>

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