Xalloumokkelos Xalloumokkelos - 4 months ago 6
jQuery Question

Setting dropdown value not working in Safari

I run this jQuery code to autoselect from a dropdown based on the

attribute. The problem is that it does not run on Safari.

document.addEventListener('DOMContentLoaded', function() {
.setAttribute('selected', 'selected');

Any help on how to edit the code to run on Safari?

Please find this JSFiddle https://jsfiddle.net/6uh57nz3/1/ even if it is not working on this, you have the complete code.


Don't know why, but setAttribute is not working in Safari. But, setting the property value of the DOM element works. And this works in all browsers.

document.querySelector('option[data-id="' + param1 + '"]')
    .selected = 'selected';

Updated Fiddle