Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.5.0.min.js"> </script> </head> <body> <p> Select one of the proposed options: <select id="selectId"> <option value="firstEl">First Element</option> <option value="secondEl">Second Element</option> </select> </p> <button onclick="addOption()"> Add Element </button> <script type="text/javascript"> function addOption() { optText = 'New elemenet'; optValue = 'newElement'; $('#selectId').append(`<option value="${optValue}">${optText}</option>`); } </script> </body> </html>