I am trying to set a value to a hidden form element by selecting their Id and not their name attribute. The hidden element has id="user_lat and name="user_lat". How can I do that?
I seem to be able to select by name:
$("input[name='user_lat']").val(results[0].geometry.location.lat());
MY attempt at selecting by id below does not work:
$("input #user_lat").val(results[0].geometry.location.lat());
If the id is to be applied to the input, the selector can have no spaces:
If you place a space between
inputand#user_lat, the selector attempts to match a child of the input, which doesn’t make much sense. It would be like having the following markup:Removing the space matches any input that contains the ID: