Bug Tracker

Opened 11 years ago

Closed 11 years ago

#12336 closed bug (fixed)

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.

Change History (4)

comment:2 Changed 11 years ago by dmethvin

Component: unfiledmanipulation
Keywords: ie6 ie7 ie8 added
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.

comment:3 Changed 11 years ago by gibson042

Milestone: None1.9

comment:4 Changed 11 years ago by Dave Methvin

Resolution: fixed
Status: openclosed

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

Changeset: bbdf957e9886212cac9b72ee9dedd73118aa8427

Note: See TracTickets for help on using tickets.