| 1 |
<!DOCTYPE html> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta charset="UTF-8"> |
| 5 |
<title>dropdown</title> |
| 6 |
</head> |
| 7 |
<body> |
| 8 |
<!-- 1. Define some markup --> |
| 9 |
<button type="button">Select</button> |
| 10 |
<select> |
| 11 |
<option>Option 1</option> |
| 12 |
<option selected>Option 2</option> |
| 13 |
<option>Option 3</option> |
| 14 |
</select> |
| 15 |
|
| 16 |
<!-- 2. Include library --> |
| 17 |
<script src="../dist/select.js"></script> |
| 18 |
|
| 19 |
<!-- 3. Select! --> |
| 20 |
<script> |
| 21 |
var dropdown = document.querySelector('select'); |
| 22 |
var button = document.querySelector('button'); |
| 23 |
|
| 24 |
button.addEventListener('click', function(e) { |
| 25 |
var selected = select(dropdown); |
| 26 |
console.log(selected); |
| 27 |
}); |
| 28 |
</script> |
| 29 |
</body> |
| 30 |
</html> |