Bug Tracker

Modify

Ticket #3041 (closed bug: wontfix)

Opened 5 years ago

Last modified 15 months ago

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

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

comment:1 Changed 5 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 5 years ago by flesler

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

Changed 5 years ago by pbcomm

comment:3 Changed 5 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 5 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 follow-up: ↓ 6 Changed 5 years ago by pbcomm

Flesler, This is a jQuery bug.

comment:6 in reply to: ↑ 5 Changed 5 years 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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.