1$(".js-example-placeholder-single").select2({
2 placeholder: "Select a state",
3 allowClear: true
4});
1Placeholder attribute does not exist for the <select> tag.
2But there are some ways to make a placeholder for the select box.
3The easiest way of making a placeholder for the <select> element is using the disabled and selected attributes with the HTML5 hidden global attribute.
4
5<select name="monthname" required>
6 <option value="" selected disabled hidden>Select Month</option>
7 <option value="Jan">January</option>
8 <option value="Feb">February</option>
9 <option value="Mar">March</option>
10 <option value="Apr">April</option>
11 <option value="May">May</option>
12 <option value="Jun">June</option>
13 <option value="Jul">July</option>
14 <option value="Aug">August</option>
15 <option value="Sep">September</option>
16 <option value="Oct">October</option>
17 <option value="Nov">November</option>
18 <option value="Dec">December</option>
19</select>