Skip to main content

Bug Tracker

Side navigation

#4802 closed bug (worksforme)

Opened June 22, 2009 10:49AM UTC

Closed October 21, 2010 08:24PM UTC

Last modified March 15, 2012 03:50PM UTC

$(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

Attachments (0)
Change History (4)

Changed June 23, 2009 01:22AM UTC by dmethvin comment:1

Please attach a complete test case demonstrating the problem.

Changed October 21, 2010 08:24PM UTC by addyosmani comment:2

keywords: chromechrome selected attr
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/

Changed July 15, 2011 10:51PM UTC by tyler@theloveofcode.com comment:3

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('');
	}
});

Changed July 15, 2011 10:54PM UTC by rwaldron comment:4

component: coreattributes
priority: majorhigh