Bug Tracker

Ticket #3041 (closed bug: wontfix)

Opened 7 months ago

Last modified 7 months ago

appendTo does not add option text to select box in IE

Reported by: pbcomm Assigned to: anonymous
Type: bug Priority: minor
Milestone: 1.3 Component: core
Version: 1.2.6 Keywords:
Cc: Needs: Review

Description

<select id="choose"></select> var option = document.createElement('option'); option.text = 'text'; option.value = 'value'; jQuery(option).appendTo('#choose');

The code above adds the options but does not display the text in the select box in IE.

Attachments

Change History

  Changed 7 months ago by pbcomm

This is due to: IE and Opera are missing .innerHTML support for TABLE-related and SELECT elements and should be considered major.

  Changed 7 months ago by flesler

Do you have a link that explains what you are saying here ?

Changed 7 months ago by pbcomm

  Changed 7 months ago by flesler

I meant about your first comment

This is due to: IE and Opera are missing .innerHTML support for TABLE-related and SELECT elements and should be considered major.

Do you mean this is a browser bug ? or jQuery's ? could you add more detail and if possible, some links ?

  Changed 7 months ago by pr

http://support.microsoft.com/kb/276228

however one thing I noticed was

This does not work in IE6/IE7

var option = document.createElement('option');
option.text = 'test';
option.value = 'test';
jQuery(option).appendTo('#choose');

this one does work in IE6/IE7 and Firefox (just changing the order

var option = document.createElement('option');
jQuery(option).appendTo('#choose');
option.text = 'test';
option.value = 'test';

follow-up: ↓ 6   Changed 7 months ago by pbcomm

Flesler, This is a jQuery bug.

in reply to: ↑ 5   Changed 7 months ago by flesler

  • status changed from new to closed
  • resolution set to wontfix

Replying to pbcomm:

Flesler, This is a jQuery bug.

You need to justify statements like this one. I tried this without jQuery, just plain Javascript and it still fails.

This is an odd IE bug. To work around you just need to set the 'text' after appending it, or use:

option.appendChild(document.createTextNode('test'));

That is actually the consistent way of doing this for any node. If you use jQuery:

$('#choose').append('<option value="test">test</option>');
// or
$('<option />').val('test').text('test').appendTo('#choose');

You shouldn't get any trouble as the attribute 'text' is never used.

I'll close this as there's no sense in catching this in my opinion as you have a ton of workarounds.

Note: See TracTickets for help on using tickets.