#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 14 years ago by
comment:2 Changed 12 years ago by
Keywords: | selected attr added |
---|---|
Resolution: | → worksforme |
Status: | new → closed |
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 12 years ago by
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 12 years ago by
Component: | core → attributes |
---|---|
Priority: | major → high |
Note: See
TracTickets for help on using
tickets.
Please attach a complete test case demonstrating the problem.