Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery attr Select on Dropdown not working Mac Safari

I have a snippet where a customer presses a button on the webpage.

This button should select an option in a hidden select box and update a few hidden fields on the page. It works on all platforms and browsers accept on Safari on the Mac.. the dropdown does not get updated.

Tracked it down to

$('#selectSize option[id=Bespoke]').attr('selected', 'selected');

The dropdown does not update but everything else works - only on Safari on the Mac.

Fiddle is here: http://jsfiddle.net/XPD25/10/

like image 743
TheBlackBenzKid Avatar asked Dec 11 '13 12:12

TheBlackBenzKid


2 Answers

You can use .prop instead:

$('#selectSize option[id=Bespoke]').prop('selected', true);

Also, IDs are unique so there is no need for the additional bits in the selector:

$("#Bespoke").prop("selected", true);
like image 178
CodingIntrigue Avatar answered Sep 22 '22 11:09

CodingIntrigue


try this

$('#selectSize option[id=Bespoke]').prop('selected', true);
like image 36
Amit Avatar answered Sep 19 '22 11:09

Amit