javascript – Meaning of append syntax

Question:

$("#add_city_btn2").click(function() {
    var city = $("#add_city2").val();
    $("#cities2").append($("<option>", { text: city, selected: "selected"})).change();
    $("#add_city2").val('');
    return false;
});   

what does the line below this code mean? mainly didn't understand the part between braces.

 $("#cities2").append($("<option>", { text: city, selected: "selected"})).change();           

Answer:

A new option is created with the text (description), which is contained in the city variable and is marked as selected option.

{ text: city, selected: "selected"}
Scroll to Top