Bug Tracker

Opened 12 years ago

Closed 11 years ago

Last modified 8 years ago

#3041 closed bug (wontfix)

appendTo does not add option text to select box in IE

Reported by: pbcomm Owned by:
Priority: minor Milestone: 1.3
Component: core Version: 1.2.6
Keywords: Cc:
Blocked by: Blocking:

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 (1)

choose.html (625 bytes) - added by pbcomm 11 years ago.
http://pbcomm.mine.nu:81/jquery/choose.html

Download all attachments as: .zip

Change History (7)

comment:1 Changed 11 years 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.

comment:2 Changed 11 years ago by flesler

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

comment:3 Changed 11 years 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 ?

comment:4 Changed 11 years 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';

comment:5 Changed 11 years ago by pbcomm

Flesler, This is a jQuery bug.

comment:6 in reply to:  5 Changed 11 years ago by flesler

Resolution: wontfix
Status: newclosed

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.