0

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.

enter image description here

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>
Beginner
  • 171
  • 1
  • 13
  • 1
    Someone asked a similar question before, [Here ](http://stackoverflow.com/questions/4599975/html-select-box-options-on-hover) is a link. – Richard Paez May 09 '17 at 18:04

1 Answers1

2

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>
A.J. Uppal
  • 19,117
  • 6
  • 45
  • 76