jQuery change hover to click -
i altered following code , replaced .hover .click. working fine except lack of "offclick" function. .hover no issue. how add account clicking off element. ul visibility should 'hidden' when clicking off, outside, etc.
$(document).ready(function(){ if($("ul.dropdown").length) { $("ul.dropdown li").dropdown(); } }); $.fn.dropdown = function() { return this.each(function() { $(this).click(function(){ $(this).addclass("click"); $('> .dir',this).addclass("open"); $('ul:first',this).css('visibility', 'visible'); },function(){ $(this).removeclass("click"); $('.open',this).removeclass("open"); $('ul:first',this).css('visibility', 'hidden'); }); }); }
the hover event has 2 states, in other words, hover event there 2 different events used behind scene , these mouseenter , mouseleave when hover on element mouseenter event gets fired , on hovering off element mouseleave event gets fired, in case, can't convert event click using 2 methods hover instead, declare 1 click event handler (function) element. example, may this:
$('#element').on('click', function(e){ //... }); if want change state of element when element gets clicked should catch click event element clicking on tnother element may opposite thing. example, may register click event on $('body') when click happens on body may opposite thing.
Comments
Post a Comment