jquery dropdown menu code example
Example 1: jquery dropdown select
$('select>option:eq(3)').prop('selected', true);
Example 2: html create drop down list
<html>
<head>
<title>Selection Inputs</title>
</head>
<body>
<form>
<label for="selector"> <!-- Can add label if want -->
<p>A "select" element allows users to input from a selection:</p>
<select id="selector"> <!-- Use "select" to create object -->
<option>Option 1</option> <!-- Add all applicable options -->
<option>Option 2</option>
<option selected>Option 3</option> <!-- add selected to change default from first option -->
<optgroup label="Group"> <!-- To create nested options for categories use "optgroup" -->
<option>Option 4</option>
<option>Option 5</option>
</select>
</label>
</form>
</body>
</html>
Example 3: dropdown menu jquery
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Dropdown Example</h2>
<p>The data-toggle="dropdown" attribute is used to open the dropdown menu.</p>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" id="menu1" type="button" data-toggle="dropdown">Dropdown Example
<span class="caret"></span></button>
<ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">HTML</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">CSS</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">JavaScript</a></li>
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">About Us</a></li>
</ul>
</div>
</div>
</body>
</html>
Example 4: jquery dropdown select
$("#element-id").val('the value of the option');