-1

I have one drop-down with ul and li tag. It is working on click. I'm trying to open drop-down on mouse hover not a click. How can i achieve this.

<div class="ms-parent form-control">
    <button type="button">
        <span class="placeholder">Choose Anyone</span>
    </button>

    <div class="ms-drop bottom" style="display: none;">
        <ul>
            <li class="ms-select-all">
            <li>
            <label>
                <input type="checkbox" value="Abu Dhabi" undefined="">
                Computer
            </label>
            </li>
            <li>
            <label>
                <input type="checkbox" value="Al Ain" undefined="">
                Keyboard
            </label>
            </li>
            <li>
        </ul>
    </div>
</div>

The output is like normal html select drop-down. But i am looking to open dropdown on mouse hover event.

6
  • use hover function of jquery Commented Jan 8, 2015 at 13:48
  • @MahenderSingh Including jQuery for this reason alone would be superfluous. This can be accomplished using CSS :hover... Commented Jan 8, 2015 at 13:53
  • I believe you're current markup is invalid. I don't believe you can nest an <li> element directly within another <li> element. You can nest a new unordered list <ul> and then new <li> element's in that list however... Commented Jan 8, 2015 at 13:55
  • There are lots and lots of tutorials out there for such functionalities. Have you checked them? If yes, provide the references or snippets. Then, mention where you have stucked and ask for help from community. Commented Jan 8, 2015 at 13:56
  • Duplicate question - stackoverflow.com/questions/4599975/… Commented Jan 8, 2015 at 13:57

2 Answers 2

1

$(document).ready(function(){
  
  
  $('#btnToChoose').hover(
         function () {
           
           $('#content').show();
         }, 
         function () {

         }
     );
  
  

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="ms-parent form-control">
    <button type="button" name="btnToChoose" id="btnToChoose">
        <span class="placeholder">Choose Anyone</span>
    </button>

    <div id='content' class="ms-drop bottom" style="display: none;">
        <ul>
            <li class="ms-select-all">
            <li>
            <label>
                <input type="checkbox" value="Abu Dhabi" undefined="">
                Computer
            </label>
            </li>
            <li>
            <label>
                <input type="checkbox" value="Al Ain" undefined="">
                Keyboard
            </label>
            </li>
            <li>
        </ul>
    </div>
</div>

Change Design as per your convenience.

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

Comments

0
  $('#btnToChoose')
  .on('mouseenter', function () { $('#content').show(); })
  .on('mouseleave', function () { $('#content').hide(); });

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.