Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery off click function? [duplicate]

this may sound like a silly questions but is there something I can call for offclick events for exmaple I have this currently;

$("#frame_left").click(function() {
    $("#navLeft").show();
});

I want to hide the #navLeft content once a user has clicked off of the radio button?

like image 887
Nat Avatar asked Mar 27 '13 20:03

Nat


2 Answers

Add a click event for the entire document:

$(document).click(function(e) {
  $('#navLeft').hide();
});

Then stop propagation on the element, so it doesn't bubble up to the document:

$("#frame_left").click(function(e) {
  e.stopPropagation();
  $("#navLeft").show();
});

http://api.jquery.com/event.stopPropagation/

like image 181
Blazemonger Avatar answered Oct 20 '22 05:10

Blazemonger


This should work for you:

$('html').click(function() {
    $("#navLeft").hide();
});

And then be sure to prevent the event from propagating when clicking the #frame_left element:

$("#frame_left").click(function(e) {
    $("#navLeft").show();
    e.stopPropagation();
});
like image 26
p.s.w.g Avatar answered Oct 20 '22 04:10

p.s.w.g