I need to change background color depending on the visibility of dropdown list.
Can anyone help? It won't turn to red when I click outside of the menu.
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
-
- <script>
- $(document).on('click','body', function(){
- if(jQuery(".selector").is(":focus")){
- $("body").css("background-color","green");
- } else{
- $("body").css("background-color","red");
- }
- });
- </script>
- <html>
- <select class="selector">
- <option value="berlin" data-calculation="0">Berlin</option>
- <option value="london" data-calculation="0">London</option>
- <option value="sydney" data-calculation="0">Sydney</option>
- <option value="tokyo" data-calculation="0">Madagaskar</option>
- </select>
- </html>