JQuery popup menu selected = selected in Safari not working

I have a multi-tab subscription form. You can click back and forth in this form.

For dropdowns, I use jquery to pre-select the previous selection, so people don’t need to re-answer this specific question when clicking on it back.

This script is great for Chrome and Firefox, however for Safari it doesn't work at all. Somehow I just can't get this to work.

Can you look at him and say what I'm doing wrong?

script:

if (repeat_visit !== '') { $('#repeatVisit').find('option').each(function(){ if ($(this).val() === repeat_visit) { $(this).attr('selected','selected'); } }); } 

The attribute is set to a parameter so that it looks like this: Yes

I see this happening, but it seems that Safari doesn't change the page when the selected attribute is added after the page loads. Therefore, I need to call this change event.

+6
source share
1 answer

I found the answer!

You can use .prop ('selected', true) instead of atr ('selected', 'selected');

+24
source

Source: https://habr.com/ru/post/954591/