Bug Tracker

Ticket #12336 (closed bug: fixed)

Opened 2 years ago

Last modified 22 months ago

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:
Blocking: Blocked by:

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

comment:1 Changed 2 years ago by anonymous

comment:2 Changed 2 years ago by dmethvin

  • Keywords ie6 ie7 ie8 added
  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to manipulation

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 2 years ago by gibson042

  • Milestone changed from None to 1.9

comment:4 Changed 22 months ago by Dave Methvin

  • Status changed from open to closed
  • Resolution set to fixed

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

Changeset: bbdf957e9886212cac9b72ee9dedd73118aa8427

Note: See TracTickets for help on using tickets.