How to set the radio button to the checked state?

Like using js or jquery when the page loads to set the radio button with a certain value (stored in the variable val) status checked?

On the page there are several radio buttons:
<input type="radio" name="filter" value="10">
<input type="radio" name="filter" value="20">
<input type="radio" name="filter" value="30">

there is a variable:
let val = 30;

Accordingly, it is necessary that the radio button with value="30" has been checked at boot time.
April 7th 20 at 15:28
1 answer
April 7th 20 at 15:30
If quite simply, like this:
// $('[value=30]').prop('checked', true);
$('[value=' + val + ']').prop('checked', true);
Can string literals be used and will be easier. Well, it's that if you screwed babel ( little or not)
$(`[value=${val}]`).prop('checked', true); - magali.Armstrong87 commented on April 7th 20 at 15:33

Find more questions by tags JavaScriptjQuery