1 Replies - 639 Views - Last Post: 08 October 2012 - 07:36 PM

#1 rbflowers  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 48
  • Joined: 10-February 12

JQuery if(certain area clicked) statement not working

Posted 25 September 2012 - 05:31 PM

Hey, I have written some code where a box opens/closes if any part of the box other than a link is clicked. If a link is clicked, I don't want the box to close.

 $("#b").bind("click", function (e) {
        var $target = $(e.target);
        if (!($target.is('a'))) {
            //if height is normal
            if (open[2] == 'n') {
                openbox(this);
            }
            //height is bigger
            else {
                closeBox(this);
            }
        }
    });


This works.

I want to also check if an area inside a fieldset is clicked. If so, I don't want the box to close because I want the user to be able to fill in a form, but my code doesn't work:

 $("#b").bind("click", function (e) {
        var $target = $(e.target);
        if (!($target.is('a')) && !($target.is('fieldset')) ) {
            //if height is normal
            if (open[2] == 'n') {
                openbox(this);
            }
            //height is bigger
            else {
                closeBox(this);
            }
        }
    });


i also tried:
if(!($target.is('a','fieldset')))

but that didn't work. I also tried another if statement under the check for !a

Help please...

Is This A Good Question/Topic? 0
  • +

Replies To: JQuery if(certain area clicked) statement not working

#2 sas1ni69  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 431
  • Joined: 04-December 08

Re: JQuery if(certain area clicked) statement not working

Posted 08 October 2012 - 07:36 PM

Have you tried other events? Like focus() perhaps. Take a look around the documentation and experiment with it. Or maybe you could post a bit more of your code so I could help you better :lol:

Oh BTW the link for the events documentation is http://api.jquery.com/category/events/

EDIT: Added Link

This post has been edited by sas1ni69: 08 October 2012 - 07:37 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1