Note that there are some explanatory texts on larger screens.

plurals
  1. POApplying css with jQuery stops <select> from showing drop down list
    primarykey
    data
    text
    <p>So I've got some <code>&lt;select&gt;</code> tags that I would like to show the entire contents in IE. I've looked around and found a <a href="https://stackoverflow.com/questions/73960/dropdownlist-width-in-ie">few</a> <a href="https://stackoverflow.com/questions/682764/select-dropdown-with-fixed-width-cutting-off-content-in-ie">fixes</a>, but I don't want to include YUI since I'm already using jQuery elsewhere, and would prefer to keep the selects on the page instead of replacing it with DIVs.</p> <p>In the code that I've come up with, FF3 works great. In Internet Explorer (6,7,8) the first click on the <code>&lt;select&gt;</code> flashes the drop down and then it disappears. I've tried <code>focus</code> and <code>mousedown</code> in place of the <code>click</code> event in the code, no success.</p> <p>If I remove both of the setting of <code>element.css</code> in <code>autoWidth</code> the drop downs work as expected, without the bonus of having a nice width. Does anyone know what would cause the setting of the css to make the drop down fail in IE?</p> <pre><code>&lt;head&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var count = 0; autoWidth = function(e) { $element = $(e.target) $element.css("width","auto"); if($element.width() &lt; $element.data("originalWidth")) { $element.css("width", $element.data("originalCSSWidth")); } } resetWidth = function(e) { $element = $(e.target) $element.css("width", $element.data("originalCSSWidth")); $("#counter").text(++count); } recordEvent = function(e) { $("#event").text($("#event").text() + " " + e.type); } dropDownIEWidthFix = function() { //if($.browser.msie) //{ $dropDown = $(this); $dropDown.data("originalWidth", $dropDown.width()); $dropDown.data("originalCSSWidth", $dropDown.css("width")); $dropDown.blur(recordEvent); $dropDown.blur(resetWidth); $dropDown.change(recordEvent); $dropDown.change(resetWidth); $dropDown.click(recordEvent); $dropDown.click(autoWidth); //} }; $(function() { $("select.officeItemList").each(dropDownIEWidthFix); }); function trackingSelectionChanged(select) { $("#event").text($("#event").text() + " inlineOnChange"); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div style="overflow:hidden;width:148px;"&gt; &lt;select class="officeItemList" style="width:148px;" onchange="trackingSelectionChanged(this);"&gt; &lt;option value="1"&gt;erasersdffffffffffeeefefsdfsdfsdfsdfsdfsdfsdfsdfsdfdsfsdfefesf&lt;/option&gt; &lt;option value="3"&gt;pencil&lt;/option&gt; &lt;option value="4"&gt;ruler&lt;/option&gt; &lt;option value="5"&gt;ink&lt;/option&gt; &lt;option value="7"&gt;A4 paper&lt;/option&gt; &lt;option value="8"&gt;A3 paper&lt;/option&gt; &lt;option value="9"&gt;erasersdffffffffffeeefefsdfsdfsdfsdfsdfsdfsdfsdfsdfdsfsdfefesf&lt;/option&gt; &lt;option value="10"&gt;executive&lt;/option&gt; &lt;option value="11"&gt;janitor&lt;/option&gt; &lt;option value="12"&gt;developer&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div style="overflow:hidden;width:160px;"&gt; &lt;select class="officeItemList" style="width:160px;" onchange="trackingSelectionChanged(this);"&gt; &lt;option value="3"&gt;pencil&lt;/option&gt; &lt;option value="4"&gt;ruler&lt;/option&gt; &lt;option value="5"&gt;ink&lt;/option&gt; &lt;option value="7"&gt;A4 paper&lt;/option&gt; &lt;option value="8"&gt;A3 paper&lt;/option&gt; &lt;option value="9"&gt;erasersdffffffffffeeefefsdfsdfsdfsdfsdfsdfsdfsdfsdfdsfsdfefesf&lt;/option&gt; &lt;option value="10"&gt;executive&lt;/option&gt; &lt;option value="11"&gt;janitor&lt;/option&gt; &lt;option value="12"&gt;developer&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div style="overflow:hidden;width:160px;"&gt; &lt;select class="officeItemList" style="width:160px;" onchange="trackingSelectionChanged(this);"&gt; &lt;option value="1"&gt;eee&lt;/option&gt; &lt;option value="3"&gt;pencil&lt;/option&gt; &lt;option value="4"&gt;ruler&lt;/option&gt; &lt;option value="5"&gt;ink&lt;/option&gt; &lt;option value="7"&gt;A4 paper&lt;/option&gt; &lt;option value="8"&gt;A3 paper&lt;/option&gt; &lt;option value="9"&gt;ffff&lt;/option&gt; &lt;option value="10"&gt;executive&lt;/option&gt; &lt;option value="11"&gt;janitor&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; AdjustWidth fired :&lt;span id="counter"&gt;&lt;/span&gt; times &lt;div id="event"&gt;&lt;/div&gt; &lt;/body&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload