views:

648

answers:

2

I have an image that opens the jQuery UI Slider div on click and allows users to set a value by dragging the handle. What I'm trying to do now is hide that handle when the user clicks anywhere else on the page, but the regular .blur event doesn't seem to work.

$("#openPriceToSliderGif").click(function(){
        $("#slider-vertical").show();
        $("#slider-vertical").focus();
    });
    $("#slider-vertical").blur(function () {
         $("#slider-vertical").hide();
    });
+1  A: 

Probably you will have a better luck on defining global onclick handler and there you need to check if source of event is not your slider. If not - do your magic.

Basically - if you spinner doesn't include element such as text field or link it will not support focus/blur

DroidIn.net
Let me se if I get this right.What you saying is, a function should trigger every time I click somewhere on the page. There I should hide my slider unless the click happend on my gif that should show my slider?I came up with this code but i have a problem finding id of element i clicked on. $(this).id is clearly not working...$(this.document).click(function () { if ($(this).id != $("#openPriceToSliderGif").id) $("#hiddenPriceTo").hide(); });
Leon
you should use slider.bind("click", function(e){}), (read this page http://is.gd/2wxvy for details). Now - the anonymous function will have e parameter which is the Event (http://is.gd/2wxAg) - that contains all sorts of useful info that can tell you where the click has occur. Basically this method means "bind me to the click anywhere in the window". BTW if you don't want any further processing when you done with your logic - simply return false from your handler function
DroidIn.net
Thanks for this. I tried to vote for your answer but I'm required to have at least reputation 15. Will vote later ;)
Leon
np - so this did work for you? Actually - I think this question is good answer to what you should learn first: language or framework :)
DroidIn.net
A: 

Ok, this is what I have put together to make this work. Thanx DroidIn.net for your help.

$(document).bind("click", function(e){
      if(e.target.id != $("#openPriceToSliderGif").attr("id"))
        $("#slider-vertical").hide();
      return false;
    });

    $("#openPriceToSliderGif").click(function(){
        $("#slider-vertical").toggle();
    });
Leon