1

I have the following inline styles for a dropdown menu list. I do not know how to make it in to 'click' using jQuery.

<button class="btn btn-primary mw" data-toggle="dropdown"><span class="caret">Subject</span></button>
  
  <div class="dropdown-menu">

     <a class="dropdown-item Business" onclick="selectBusiness()"> Business</a>
     <a class="dropdown-item ICT" onclick="selectICT()"> ICT</a>
     <a class="dropdown-item Arts" onclick="selectArts()"> Arts</a>

  </div>

More information:

I tried to do this following code for a button and it's working fine. But as I said I do not know how to make it work for a dropdown menu.

var btn = document.querySelector("button.selectAll");
btn.addEventListener("click", selectAll);
....

Your input would be greatly appreciated!

1 Answer 1

2

If you want to use jQuery, you can add listener to the classes of each <a> inside your dropdown.

$(".Business").on('click', function() {
//selectBusiness() or your code here
});

$(".Arts").on('click', function() {
//selectarts() or your code here
});

$(".ICT").on('click', function() {
//selectICT() or your code here
});

Another solution would be to add a single listener for all your dropdown-items and then checking the content of the selected one.

$(".dropdown-item").on('click', function() {
    switch ($(this).text()) {
        case "Business": 
        selectBusiness();
        break;


    }

});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.