Bug Tracker

Opened 10 years ago

Closed 9 years ago

Last modified 8 years ago

#4802 closed bug (worksforme)

$(elem).attr('selected','selected') in Chrome don't work

Reported by: todoshcenko Owned by:
Priority: high Milestone:
Component: attributes Version: 1.2.6
Keywords: chrome selected attr Cc:
Blocked by: Blocking:

Description

$(elem).attr('selected','selected') don't work.

JavaScript Debugger say: "uncaught exception TypeError: Cannot read property 'selectedIndex' of null".

elem.selected = 'selected'; - work

Chrome version - 2.0.172.31

Change History (4)

comment:1 Changed 10 years ago by dmethvin

Please attach a complete test case demonstrating the problem.

comment:2 Changed 9 years ago by addyosmani

Keywords: selected attr added
Resolution: worksforme
Status: newclosed

I've tested this using jQuery 1.4.3 and both the latest Chrome (and older versions) but I haven't been able to reproduce the issue experienced. Please see here for a live test case http://jsfiddle.net/MUJtD/1/

comment:3 Changed 8 years ago by tyler@…

I had this same issue using jQuery version 1.6. The following code does not work in Chrome 12 (PC)

jQuery('#mydiv select').live('change', function() {
	if (jQuery(this).val() != '') {
		jQuery('#otherdiv select option[value="'+ jQuery(this).find('option:selected').val() +'"]').attr('selected', 'selected');
	} else {
		jQuery('#otherdiv select option').removeAttr('selected');
	}
});

The following work around does work.

jQuery('#mydiv select').live('change', function() {
	if (jQuery(this).val() != '') {
		jQuery('#otherdiv select').val( jQuery(this).find('option:selected').val() );
	} else {
		jQuery('#otherdiv select').val('');
	}
});

comment:4 Changed 8 years ago by Rick Waldron

Component: coreattributes
Priority: majorhigh
Note: See TracTickets for help on using tickets.