1

I am trying to make a dropdown selection with jquery over bootstrap, for me this seems to be hard to be done. This is my code:

<div id="green" class="X dropdown mt-4 pb-3">
    <button id="btn" type="button" class="btn btn-default dropdown-toggle " data-toggle="dropdown">Select
        languange</button>

    <button class="dropdown-menu">
        <a id="1" class="dropdown-item" href="#">English</a>
        <a id="2" class="dropdown-item" href="#">German</a>
        <a id="3" class="dropdown-item" href="#">French</a>
    </button>
</div>

$('.classdropdwn').click(function(){$('.classbutton').html( $(this).text)})

also I have tried sometrhing like this:

$(document).ready(function(){
    $('#btn').click(function(){
        $("#btn").empty()
        $("#btn").html( $(this).text)
    });                 
});

Thank you for your help!

aynber
  • 22,380
  • 8
  • 50
  • 63
A B
  • 177
  • 1
  • 3
  • 13

1 Answers1

0

You can do like this also is a sample code I have done

$(document).ready(function(){
    $('#btn').click(function(){
     $('.dropdown-menu').toggle();
    });                 
});
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="green" class="X dropdown mt-4 pb-3">
    <button id="btn" type="button" class="btn btn-default dropdown-toggle " data-toggle="dropdown">Select
        languange</button>

    <button class="dropdown-menu">
        <a id="1" class="dropdown-item" href="#">English</a>
        <a id="2" class="dropdown-item" href="#">German</a>
        <a id="3" class="dropdown-item" href="#">French</a>
    </button>
</div>
Husna
  • 1,286
  • 4
  • 19
  • 48