how to get text with option:checked and write this value to <span> . I wrote a script but it does not work correctly, instead of adding a new element to existing ones, for example: one (already) I chose two and in the field there should be <span>один</span> , and add this one New element - <span>два</span> - and my script adds one again and you get <span>один</span><span>один</span><span>два</span> how can I fix this?
js:
$(".subway-location").change(function() { $(this).children("option").filter(":checked").each(function() { var x = $(this); console.log(x); var b = x.text(); $("#metroDistance").css("display", "block"); $("#metroDistance .info__item").append("<span class='distance-option'><span class='metro-name'>"+ b + "</span><input type='text' data-id='metro_distance'></span>"); }); }); <select class="subway-location"> <option>один</option> <option>два</option> <option>три</option> </select>