Reputation: 191
How to use the hover drop down? I want to display the value when I click the selection. For example if I click on 2, the word "Number" will become two. I can't find how to use it as I don't know the key word.
Can be this done by hover drop down menu? Or there are other ways? Thanks.
Here is the code I found.
<div class="dropdown">
<button class="dropbtn" id="drop1" >Number</button>
<div class="dropdown-content">
<a href="#">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>
</div>
</div>
Upvotes: 0
Views: 680
Reputation: 19264
Using JQuery you can do this with one line:
$("a").click(function(){$("#drop1")[0].innerHTML = this.innerHTML;});
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" id="drop1" type="button" data-toggle="dropdown">Number
<span class="caret"></span></button>
<ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">1</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">2</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">3</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">4</a></li>
</ul>
</div>
</div>
</body>
</html>
Upvotes: 2