Need a little help on this one. I am trying to write jQuery code to change the selection of a select dropdown. Following the excellent advice on here, I am using .val(). However, this doesn't remove the selected attribute, so I am also doing that.
The part where I am stuck is, I want to add the selected attribute to the new option, but the value of the new option (which is stored in the PHP value $option) has double quotation marks in it.
var shopDropdown = $(".buy__option-select__select",
$('iframe')[0].contentWindow.document);
var initialSelection = $(".buy__option-select__select > option[selected]",
$('iframe')[0].contentWindow.document);
initialSelection.attr('selected',false);
$(".buy__option-select__select",
$('iframe')[0].contentWindow.document).val('<?php echo $option ?>');
$('.buy__option-select__select > option[value="<?php echo addslashes($option) ?>"]',
$('iframe')[0].contentWindow.document).attr('selected',true);
shopDropdown.trigger('change');
Thanks!