I would like to load a select box where in the user\'s selected value will automatically appear.
I am receiving a Json data from the server with the user info. sampl
after much research, I finally went back to see the jQuery documentation that gave me the right answer :
1 / Delete all the attributes of tags that are already with the 'selected' attribute
function remove_selected(){
$("select option").removeAttr('selected');
}
2 / I use the prop() function of jQuery to assign the 'selected' attribute to the desired tag
// USE THE FUNCTION TO REMOVE ALL ATTRIBUTES ALREADY SELECTED
remove_selected();
// Set the tag
In HTML this gives :
It is clean and without burrs, thank you for your feedback and corrections, approve if you find this solution correct. Sincerely, Raf.
Source : https://api.jquery.com/prop/