Skip to main content

Bug Tracker

Side navigation

#12336 closed bug (fixed)

Opened August 17, 2012 07:19PM UTC

Closed January 06, 2013 07:21PM UTC

Calling $('#select').empty() should set options length to 0

Reported by: anonymous Owned by:
Priority: low Milestone: 1.9
Component: manipulation Version: 1.8.0
Keywords: ie6 ie7 ie8 Cc:
Blocked by: Blocking:
Description

Hi,

Consider the following HTML snippet:

<select name="s" id="s">
  <option value=""> </option>
</select>

Consider the following JavaScript snippet:

  var ohtml = '';

  ohtml += ('<option value="1">1</option>');
  ohtml += ('<option value="2">2</option>');
  ohtml += ('<option value="3">3</option>');
  
  ${'#s'}.empty().append( ohtml );

In certain conditions, this code fails in various version of IE:

http://stackoverflow.com/a/2040837/59087

Fix IE8 refresh bug (the values get set in the DOM, but the view for the drop-down does not refresh:

  ${'#s'}[0].options.length = 0;

Ideally, the jQuery empty() function would include code to set the length to 0. This would have saved some of my hair follicles.

Attachments (0)
Change History (4)

Changed August 17, 2012 07:22PM UTC by anonymous comment:1

Changed August 17, 2012 07:37PM UTC by dmethvin comment:2

component: unfiledmanipulation
keywords: → ie6 ie7 ie8
priority: undecidedlow
status: newopen

I think we'd be able to fix the oldIE bug with emptying select boxes, but only if the immediate element being emptied was a select.

The benchmark there ignores the problem of removing events and data from any options, which means in real-life situations it would leak memory. So you can't take that shortcut. In fact, we'd need to do all our standard cleanup and only then set the length to zero if it was a select.

Changed December 04, 2012 05:46AM UTC by gibson042 comment:3

milestone: None1.9

Changed January 06, 2013 07:21PM UTC by Dave Methvin comment:4

resolution: → fixed
status: openclosed

Fix #12336. Ensure oldIE really does .empty() selects.

Changeset: bbdf957e9886212cac9b72ee9dedd73118aa8427