Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i make toggle on hover in desktop and on click in mobile

HTML
HTML
<button id="bar">bar</button>
<div id="foo"></div>


CSS
CSS
#foo {
    width: 100px;
    height: 100px;
    background-color: green;
    display:none;
}


Javascript
JavaScript
$('#bar').click(function () {
    $('#foo').slideToggle('slow');
});


jsfiddle
Posted

For Hover you can implement mouseover jquery function on $('#bar').

for example
JavaScript
$('#bar').mouseover(function () {
    $('#foo').slideToggle('slow');
});


JSfiddle
 
Share this answer
 
Comments
Mohammad Kashif Nadeem 7-Jul-15 11:38am    
Your answer is incomplete. I asked that how do I make toggle On hover In desktop and an click in mobile. while you only provide hover option.
JavaScript
if (window.matchMedia("(max-width: 767px)").matches) {
    $('#bar').click(function () {
    $('#foo').slideToggle('slow');
});
	
}

 else {
    $('#bar').hover(function () {
    $('#foo').slideToggle('slow');
});
		
}	
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900