1<!doctype html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>selected demo</title>
6 <style>
7 div {
8 color: red;
9 }
10 </style>
11 <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
12</head>
13<body>
14
15<select name="garden" multiple="multiple">
16 <option>Flowers</option>
17 <option selected="selected">Shrubs</option>
18 <option>Trees</option>
19 <option selected="selected">Bushes</option>
20 <option>Grass</option>
21 <option>Dirt</option>
22</select>
23<div></div>
24
25<script>
26$( "select" )
27 .change(function() {
28 var str = "";
29 $( "select option:selected" ).each(function() {
30 str += $( this ).text() + " ";
31 });
32 $( "div" ).text( str );
33 })
34 .trigger( "change" );
35</script>
36
37</body>
38</html>
39