I want to ask you, how can i implement an element into a pull down list with jQuery. I have the code below.
I want to implement an <option value="fiat">Fiat</option>"> element by clicking the button. However the code will not work. I also tried to use .html() and .replaceWith() functions, but it will not work too. Does someone an idea?
$(document).ready(function(){ $("#btn1").click(function(){ $("select").append("<option value="fiat">Fiat</option>"); }); }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="vw">VW</option> <option value="audi">Audi</option> </select> <button id="btn1">Add option element</button>
'to wrap the string and"inside the string:$("select").append('<option value="fiat">Fiat</option>');