I want to apply value from input to select when document is ready. Everything works fine.
Do you recommend to check if both select#city and input#city_hidden exist to make this code better?
$(document).ready(function ()
{
$("select#city").val($("input#city_hidden").val());
});
The decision depends on numerous factors, not just this line of code.
Technically, you don’t need to check if select#city exists. If it doesn’t, jQuery will just do nothing as the $(“select#city”) selector will be empty.