I use the drop-down list from the bootstrap, and I would like the button to change its text, depending on which of the two elements of the drop-down I click. The text changes according to the pressed element, but the carriage disappears after the first change, etc. I want to save the carriage in the button!
<head> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> </head> <body> <div class="dropdown"> <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" value="Fast">Fast <span class="caret"></span></button> <ul class="dropdown-menu" value="Fast"> <li onclick="dropdown(this.innerHTML);">Fast</li> <li onclick="dropdown(this.innerHTML);">Accurate</li> </ul> </div> <script> function dropdown(val){ var y = document.getElementsByClassName('btn btn-default dropdown-toggle'); var aNode = y[0].innerHTML=val; } </script>
Sneb source share