views:

43

answers:

3

I currently have three Divs and only one of them is in focus at a given time. All of them line up in a film strip fashion. When I click a DIV not in focus, the current one moves to the left or right (depending on the direction) and the new one comes into focus.

The divs can have content that has links. So my problem is that upon clicking on the divs not in focus, if I happen to click on a link, the event is captured. Is there anyway I can disable event detection for divs not in focus?

What I am looking for is something like:

if(div not in focus)
 disable all links
if (div comes into focus)
 enable all links
+2  A: 

Assuming that the active <div> has a class of Active, you can do it like this:

$('.Container div:not(.Active) a').live('click', function(e) {
    return false;
});
SLaks
@SLaks: Trying it now. Will get back. Thanks
Legend
If you want the `<div>` to respond to the click, you'll need to change it to `e.preventDefault()`.
SLaks
@Slaks: Thanks for the input. The preventDefault() thingy worked well.
Legend
@SLaks: I didn't realize that 10 mins were up :) However, I'm running into a small issue that I posted as a comment to Andy's post but I'll post it anyways. It runs fine in Firefox and Chrome but fails occasionally in Safari.
Legend
+1  A: 

In your event handler, use

if (event.target.tagName == "a") // where `event` is the 1st argument passed 
    event.preventDefault();      // to the handler

This will prevent the default action if a link was clicked and still allow the div to move into focus.

Andy E
@Andy: Thanks for the quick tip. But it works only occasionally for some reason. Do you have any idea as to why? All I am doing is if the event comes from some other div not in focus, I am using an `event.preventDefault()`. Just tested it. It works in Firefox and Chrome but sometimes fails in Safari.
Legend
+1  A: 

Sounds like a selector problem. Can't you give those divs unique ids or classes to bind click events individually?

jAndy