How can I check a switch at boot based on its value?

I have a switch value (r1) and I'm trying to use:

$ ("input: radio [val = r1]"). attr ('checked', true);

to check it out.

The fact is that I have three switches in the div, when I check one, the value of the saved button is saved.

When I reload the page, I want the page to check the switch that was last selected.

Thank!

+3
source share
2 answers

The attribute is called value. Try:

$('input:radio[value=r1]').attr('checked', 'checked');

To uncheck, you must call:

$(selector).removeAttr('checked');
+5
source

. , , .

+1

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


All Articles