سؤال

How do I show or hide a div on double click with jquery?

$("body").dblclick(function() { 
            $("#plot_on_map_form").show("medium").css({top: event.pageY,left: event.pageX});
        },
        function() {
            $("#plot_on_map_form").css({display:"none"});
    }
);
هل كانت مفيدة؟

المحلول

<div>Div</div>

$(document).dblclick(function(){
    $('div').toggle();
});

demo: http://jsfiddle.net/dth9R/

نصائح أخرى

According to jquery docs http://docs.jquery.com/Events/toggle you can try like this for show and hide

 $("li").dblclick(function() {
       if($(this).didSomeThing == true){
           $(this).backToNormal();
           $(this).didSomeThing = false;
           return;
       }
       $(this).doSomething();
       $(this).didSomeThing = true;
    });

You have used two function blocks, but in this case this will not work here.

use one function block and use jquery function toggle().

this will solve the problem.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top