So this has caused me a lot of headace. I am making a "pulldown accordion submenu" (for the lack of a better name). My script works, but only on HOVER. If I try to use .click, .on("click"), .on("click", "li") etc. nothing works. The script only works when using .hover.
NOTE! It's only the "#TopMenu" that is supposed to have the on click event. The sub-menu ("#accordion") is going to be hover.
Any ideas ?
Working:
$(document).ready(function () {
$('#accordion li').hover(function () {
$(this).find('ul').stop(true, true).slideDown()
}, function () {
$(this).find('ul').stop(true, true).slideUp()
}).find('ul').hide()
$('#TopMenu li').hover(function() {
$(this).find('li').stop(true, true).slideDown()
}, function () {
$(this).find('li').stop(true, true).slideUp()
}).find('li').hide()
});
Changing "#TopMenu" to CLICK is NOT WORKING:
$(document).ready(function () {
$('#accordion li').hover(function () {
$(this).find('ul').stop(true, true).slideDown()
}, function () {
$(this).find('ul').stop(true, true).slideUp()
}).find('ul').hide()
$('#TopMenu li').on('click', function() {
$(this).find('li').stop(true, true).slideDown()
}, function () {
$(this).find('li').stop(true, true).slideUp()
}).find('li').hide()
});
I have a working test here: http://jsbin.com/nidazuq/3/embed?html,js,output
I'm going nuts over this, I've searched high and low for a solution. please help.
ID should be unique and single for a page. You used twice in the page. Added fiddle with some changes.