Bug Tracker

Modify

Ticket #1916 (closed bug: fixed)

Opened 6 years ago

Last modified 14 months ago

Last option in SELECT is selected when options set using .html(strHtml) in Firefox/Mozilla

Reported by: doug Owned by:
Priority: major Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: Cc:
Blocking: Blocked by:

Description

Using .html() to set the options in a SELECT element selects the last option in the last regardless of which options have the 'selected' attribute. The problem occurs in Firefox 2, not IE 7.

Example, <select id="sel"></select>

$('#sel').html('<option>a</option><option selected>b</option><option>c</option>');

displays with 'c' shown as selected when it should be 'b'.

SOLUTION:

domManip: function(args, table, dir, fn) {

: return this.each(function(){

: jQuery.each( a, function(){

var elem = clone ... if ( !evalScr...

fn.call( obj...

});

/* SOLUTION BEGIN */ if (jQuery.nodeName(this, "select")) {

jQuery.each( this.options, function(){

this.selected = this.defaultSelected; Needed for Firefox, which always selects last option

});

} /* SOLUTION END */

});

}

Attachments

jquery_test.html Download (742 bytes) - added by davidserduke 5 years ago.
test case (based on description)

Change History

Changed 5 years ago by davidserduke

test case (based on description)

comment:1 Changed 5 years ago by davidserduke

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

This appears to be fixed. I suspect it was the fix [3844] that did it.

Since I didn't do it on purpose and test before and after, if someone sees a problem that I'm overlooking please reopen the bug.

comment:2 Changed 5 years ago by doug

Retested with jQuery 1.2.2 and it appears to be working. Thanks!

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.