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 Element'; optValue = 'newElement'; $('#selectId').append(new Option(optText, optValue)); } </script> </body> </html>