Bug Tracker

Opened 3 years ago

Closed 3 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:



Consider the following HTML snippet:

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

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:


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 3 years ago by dmethvin

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

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

  • Milestone changed from None to 1.9

comment:4 Changed 3 years ago by Dave Methvin

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

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

Changeset: bbdf957e9886212cac9b72ee9dedd73118aa8427

Note: See TracTickets for help on using tickets.