Adding options to a

To add options to a <select>, you need to use append(). Following is the JavaScript code −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="stylesheet" href="//">
<script src=""></script>
<script src=""></script>
<select name="mySelection" id="selectCategory">
<option value="Book">Book</option>
<option value="TV">TV</option>
   var mySelection = new Option("Mobile", "Samsung Mobile");
   $(mySelection).html("Samsung Mobile");

To run the above program, save the file name anyName.html(index.html) and right-click on the file and select the option open with live server in VS Code editor.


Updated on 15-Jul-2020 11:56:25

Previous Page Print Page Next Page